Level multiplayer treasure grove with js


#1

this is mi code:

loop {
var enemy = this.findNearestEnemy();
var coins = this.findNearestItem();
var distance = this.distanceTo(enemy);
if (coins){
var pos = coins.pos;
var x = pos.x;
var y = pos.y;
this.moveXY(x, y);
}
else if (distance < 10){
this.isReady(“cleave”);
this.isReady(“cleave”);
}
}
I have an error on line 4 that says: "distanceTo target is null"
help me please, don’t know what it could be


#2

Hint: Format your code with 3 ` back ticks so people can try the code.
The code works fine to me, but is cleaving neccesary as I saw you didn’t attack with cleave you checked if it was ready but never striking him or anything.


#3

Hint: are you sure that an enemy exists, before calculating the distance?