Need help on how to check how close an enemy is to you

please help i don’t know how to do this.
here is my code.

# Check the distance to the nearest enemy.
if enemy:

# If it comes closer than 10 meters, cleave it!

# Else, attack the "Chest" by name.

js syntax (assuming enemy and chest variables are already assigned) :

if(enemy) {
  if (this.distanceTo(enemy) < 10) {
  } else {

What is your problem exactly ?