Why wouldn't this code work?

I can’t understand why this code wouldn’t work. It says that it expects an identifier instead of the last “else”.
Seems to me if in the first ‘if(enemy)’ statement was not true, that it would skip directly to the last else statement and move the hero back to location 40, 34.

    var enemy = hero.findNearestEnemy();
   
    if(enemy) {
        var dist = hero.distanceTo(enemy); 
        
        if(dist < 5) {
            hero.attack(enemy);
        }
        else {
            hero.shield()
        }
        
    
    else {
        hero.moveXY(40, 34);
    }
}```

Can you format all of your code chances are its a bracket problem. Its easier to see the brackets when it all formatted.

From the looks of it your while loop doesnt have an ending bracket. You also need a ; at the end of hero.shield()

I cannot for I already backed out of that game.

and I thought the very last bracket closed out the ‘while true’ statement

I see what you are saying though. This is my biggest problem is keeping up with all these brackets. Looks like I didn’t have one to close out the ‘if enemy’ statement. Are lack of these brackets be why it was giving me the original error message?

Yes it possible but you also have the missing ;

You can edit your post and put in 3 backstick before and after the code still or highlight everything and click the button </> which is in the top bar of the text editior.

Thanks. Just knowing how to format my posts will help a bunch.