I see your problem. you use !=, but you need to use !==. Javascript is weird like that. Only using one equal sign means that it won’t properly check the variable. Plus, instead of doing that, personally I would suggest doing this:
while (true){
//do stuff
if (hero.pos.x == redX.x && hero.pos.y == redX.y){
break;
}
}
Thank you fuery. I tried it this code using !==, but it still seems stuck in the while loop. I will try your other suggestion and let you know how it goes.
let redX = { x: 19,y: 40};
while (hero.pos !== redX) {
var coins = hero.findItems();
var enemy = hero.findNearestEnemy();
if (enemy) {
hero.attack(enemy);
}
if (coins) {
for (var coin of coins) {
hero.move(coin.pos);
}
}
hero.move(redX);
}
hero.say("I have arrived.");