Usual day gets stuck

I’m trying to do usual day, and it gets stuck after grabbing the first coin and no longer attacks the incoming ogres.

I first thought it was a Coffeescript issue, so I tried in javascript also, but no difference.

// Defeat munchkins, collect coins. Everything as usual.
// Use AND to check existence and type in one statement.

while (true) {
    var enemy = hero.findNearestEnemy();
    // With AND, the type is only checked if enemy exists.
    if (enemy && enemy.type == "munchkin") {
        hero.attack(enemy);
    }
    // Find the nearest item.
    var item = hero.findNearestItem();
    // Collect item if it exists and its type is "coin".
    if (item && item.type == "coin") {
        hero.attack(item);
    }
}

If I comment out the item part, it kills the ogres, but obviously doesn’t grab the coins.
If I add a var i = 0; while (true) { hero.say(i); i++; in front, it looks like it stops running after the 19th cycle.

What am I doing wrong?

I just remembered they did hero.moveXY in previous exercises to grab the item, not attack.

But maybe it would be nice to get some feedback I’m doing the wrong thing?

You are attacking coins