Hi,
I completed the level…but I feel like my code is wrong or extra. Can anyone take a look and let me know where I went wrong here?
Thank you
// The artillery uses coins as a target.
// You'll be the rangefinder for the artillery.
// Write the function.
function coinDistance() {
// Find the nearest coin,
var coin = hero.findNearestItem();
// If there is a coin, return the distance to it.
if (coin) {
var distance = hero.distanceTo(coin);
return distance;
} // Else, return 0 (zero).
else {
if (distance === 0) {
return false;
}
}
}
while (true) {
var distance = coinDistance();
if (distance > 0) {
// Say the distance.
hero.say(distance);
}
}