// 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”);
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