Error: Find distance to target unity - Siege of Stonehold (JS)

Error: Find distance to target unity

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

Why is this an error.
This has’nt been an error before, but on this level it is

There probably isn’t an enemy within sight at some point; have you checked whether the enemy exists first?

@nick No, how do i do that?

To check if an enemy exists, you have to have the line of code

if (enemy) {

because an enemy has to be there for that line to work.