Blind Distance Java Script


#21

what do you mean mr. Bryukh


#22

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.


#23

it says unmatched’{ ’


#24

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


#25

what is the purpose of this


#26

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.


#27

thank you Sir I passed it yay


#28

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.


#29

Please format according to the FAQ please @Dgario_Stringfield


#30

could you link me to the page for formatting?


#31

Just place three back ticks and that is how you do it.


#32
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]


#33

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


#34
// 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.


#35

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

temp001


#36

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.


#37

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


#38

Can you post your code?