Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Help! codecombat blind distance

#1

i,am stuck at the blind distance here is the code

// 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:
hero.say(“22”);
// Say the value of enemyDistance variable.
hero.say(“11”);

#2

As the level tells you to do: if enemyDistance is greater than 0, say the value of enemyDistance. What’s with the 22 and 11? The enemy is not always one of the two. Try:

if (enemyDistance > 0) {
    hero.say(enemyDistance);
}

Or something like that (my JavaScript sucks…lol)

In the future, also be sure to correctly format your code :slight_smile:

1 Like
#3

gimme a screenshot.:sunglasses::four_leaf_clover:

1 Like
#4

hellenar you just gave me the writ code :wink:

1 Like
#5

@Hellenar gave you a solution to the part which was wrong. That is okay.

1 Like