Help on mind the trap (Javascript)

When I run this code my hero walked straight to the bombs help please?

// If you  to attack a distant enemy, your hero will charge toward it, ignoring all flags.
// You'll need to make sure you only attack enemies who are close to you!

while(true) {
    var flag = hero.findFlag();
    var enemy = hero.findNearestEnemy();
    if(flag) {
        // Pick up the flag.
        hero.say("I should pick up the flag.");
    } else if(hero.distanceToEnemy < 10);
        // Only attack if the enemy distance is < 10 meters

Hi blackknight3489,

Welcome to the forum (and sorry it’s taken so long for you to get a reply).

Have another look at this line:

else if(hero.distanceToEnemy < 10);

What code have you used to find the distance to an enemy before?

Post again if you need more help.


In this part you must correct the code as follows:

} else if (hero.distanceToEnemy <= 10) {