I have tried to follow other threads about this level, but I am still stuck. Here is my code below. Can someone please help me out?
while(true) {
var coins = hero.findItems();
var coinIndex = 0;
var nearest = null;
var nearestDistance = 9999;
while(coinIndex < coins.length) {
var coin = coins[coinIndex];
var distance = hero.distanceTo(coin);
if(distance < nearestDistance){
nearest = coin;
nearestDistance = distance;
}
coinIndex++;
}
if(nearest == coin){
hero.moveXY(coin.pos.x, coin.pos.y);
}
}