Hit and freeze help [javascript]


#1

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


#2

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


#3

ok thank you i will try that


#4

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


#5

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


#6

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


#7

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