Hit and freeze help [javascript]

this is my code

// You are trapped. Don't move, it'll be painful.

// This function checks if the enemy is in your attack range.
function inAttackRange(enemy) {
    var distance = hero.distanceTo(enemy);
    // Almost all swords have attack range of 3.
    if (distance <= 3) {
        return true;
    } else {
        return false;
    }
}

// Attack ogres only when they're within reach.
while (true) {
    // Find the nearest enemy and store it in a variable.
    var enemy = hero.findNearestEnemy();
    
    // Call inAttackRange(enemy), with the enemy as the argument
    // and save the result in the variable canAttack.
    inAttackRange();
    // If the result stored in canAttack is true, then attack!
    if (true) {
        hero.attack(enemy);

this is what happens when i try to run it

Call inAttackRange(enemy), with the enemy as the argument.

1 Like

ok thank you i will try that

thank you soo much but my hero keeps running after the enemies why is this?

1 Like

I think he will go after them until they are all dead…

can you help me with logical path because im having trouble with that now i have it up just look up logical path javascript

1 Like

Call inAttackRange(enemy), with the enemy as the argument
and save the result in the variable canAttack.