Blind Distance Java Script

does any body know how to pass blind distance on javascript it annoys me. this is what i type in .

// Tell the wizard the distance to the coming ogres.

// This function finds the nearest enemy and returns the distance to it.
function nearestEnemyDistance() {
    var enemy = hero.findNearestEnemy();
    // If there is no enemy, the function returns 0.
    var result = 0;
    if (enemy) {
        result = hero.distanceTo(enemy);
    }
    return result;
}

while (true) {
    var enemyDistance = nearestEnemyDistance();
    if (distance > 0)
        hero.say(distance);
}

my problem is I cant understand the distance thing on line 19
and I can’t get line 21 please help me anybody

You save the result of nearestEnemyDistance to enemyDistance not to distance.

distance is not a “magic” word. It’s just a variable name and you haven’t defined it.

thank you sir for helping me.

Sir what do i do on line 22

// Tell the wizard the distance to the coming ogres.

// This function finds the nearest enemy and returns the distance to it.
function nearestEnemyDistance() {
var enemy = hero.findNearestEnemy();
// If there is no enemy, the function returns 0.
var result = 0;
if (enemy) {
result = hero.distanceTo(enemy);
}
return result;
}

while (true) {
// Call nearestEnemyDistance() and
// save the result in the variable enemyDistance.
var enemyDistance = nearestEnemyDistance();
// If the enemyDistance is greater than 0:
var enemyDistance = nearestEnemyDistance();
if (hero.distanceTo > 0)
// Say the value of enemyDistance variable.
hero.say(distance);
}

Is this code that i wrote right sir

My friend is doing python and he looks up the anwsers and cheats and passes me. I try to do it the right way.

if (enemyDistance > 0) {

// This function finds the nearest enemy and returns the distance to it.
function nearestEnemyDistance() {
    var enemy = hero.findNearestEnemy();
    // If there is no enemy, the function returns 0.
    var result = 0;
    if (enemy) {
        result = hero.distanceTo(enemy);
    }
    return result;
}

while (true) 
    // Call nearestEnemyDistance() and
    // save the result in the variable enemyDistance.
    var enemyDistance = nearestEnemyDistance();
    // If the enemyDistance is greater than 0: 
    if (enemyDistance > 0) {
        // Say the value of enemyDistance variable.
        hero.say(distance);
}

is this correct Mr. Bryukh

if it works then it’s correct. Please don’t post solutions here.

sir, what do i do on line 21

are you ignoring me mr. bryukh

Is it a question? Try to run and you’ll see.

Is it a question? I don’t know what do you do on line 21 because the code has 20 lines.

No. Do you think I watch the forum all time and all post? If you want to ask me something, it’s better to use mentions and I’ll get a notification.

1 Like

I am sorry Mr.Bruyukh :cry:

I asked that because you usually replied the day I asked you something.But last time you didn’t text me for 2 days.

No problem. I didn’t get those phrases are questions. Could you explain your currnet problem?

Sir i meant line 21 with the extra comments that pop up when you reload it

hero.say(distance);

You don’t have distance variable in your code so it’s undefined. Think where you store the result of the function and use it.