Blind Distance Java Script

what do you mean mr. Bryukh

He is trying to explain to you that by the time you reach the end of your code you have
3 variables:
var enemy
var result
var enemyDistance

If you have your hero say any of those variables it will return whatever they are defined as. So lets say

var enemy = 1;
var result = 2;
var enemyDistance = 3;

you could type in
hero.say(enemy); and your hero would say 1
hero.say(result); and your hero would say 2
hero.say(enemyDistance); and your hero would say 3.

Your code has hero.say(distance);

As much as your hero wants to do what you tell him, you haven’t told him what (distance) is yet.

2 Likes

it says unmatched’{ ’

the { beside the while true on line 14 with the words that tell you what to do

what is the purpose of this

While statements have to be opened and closed just like if and else statements. It looks like (in your code above) you have:
a function that is opened with { and closed with }
An if statement that is opened with { and closed with }
Then a while(true) statement that is never opened.

These statements are essentially containers, When your code is compiled it tells the computer that while true = true, do… nothing.

Make sure you have an opening and closing curly bracket after each function, if/else/elseif statement, and every while statement.

1 Like

thank you Sir I passed it yay

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){
var distance = hero.distanceTo(enemy);

    }
    // Say the value of enemyDistance variable.
    hero.say(distance);

having issues completing the blind distance course.I believe my code is correct,but when I run it nothing happens.

Please format according to the FAQ please @Dgario_Stringfield

could you link me to the page for formatting?

Just place three back ticks and that is how you do 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){

var distance = hero.distanceTo(enemy);

    }
    // Say the value of enemyDistance variable.
    hero.say(distance);

having issues completing the blind distance course.I believe my code is correct,but when I run it nothing happens.
[/quote]

Check your code. Did you indent correctly? You should use functions for this.

1 Like
// 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: 
    
        // Say the value of enemyDistance variable.
        
}

I use Lua but the prewritten code is in Javascript.

You’re on the right track. Just need two more lines of code.

temp001

I was just reporting that the code already there when I loaded the level up was in Javascript, not Lua. Although I did pass it.

How do you do this in Python? I am struggling with it, so please help. :tired_face::frowning::anguished::weary:

Can you post your code?