Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

I need help with the usual day level

// 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();
if (item && item == “coin”) {
hero.moveXY(item.pos.x, item.pos.y);
}
}
// Collect item if it exists and its type is “coin”.

i have everything done, its under 8 statements and i defeated the ogres already but it says the statement to collect 3 coins isn’t completed and i just can’t figure it out

// 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();
if (item && item == “coin”) {
hero.moveXY(item.pos.x, item.pos.y);
}
}
// Collect item if it exists and its type is “coin”.

That is how you format your code if you are new here. But no worries. So I suggest try looking at the "Hints"perhaps it gives more specific information about the goals of this level.

What is your equipment this is mine I have advanced equipment(PS I subscribed), but I am sure you have OK equipment.

So try moving the second to last “}” four spaces

Sorry, but that is not correct either Jeremy…there are no indentations.

@Daneisys_F, you can learn how to properly format here: [Essentials] How To Post/Format Your Code Correctly

PS but that is how my code is and it works

In the case of JS, indentation is not critical, like it is with PY, but it does help with troubleshooting the code…makes it easier to read.

You can have your code automatically ‘prettified’ for you, by clicking on the smiley button:
image

PS my code is exactly like his except the second to last “}” is four spaces different

Daneisys_F I’m guessing you’ve tried already, but have you submitted your code a few times? It looks right to me; I think coins are randomly generated, and occasionally they’re too far away so they disappear before they can be collected?

@Daneisys_F, take a look at these two statements:

if (enemy && enemy.type == “munchkin”)
if (item && item == “coin”)

One works, but the other does not…

1 Like

And, here is your code properly formatted:

// 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();
    if (item && item == "coin") {
        hero.moveXY(item.pos.x, item.pos.y);
    }
}    // Collect item if it exists and its type is "coin".

oh yes the item part u should say “item.type”/ item.type

do hero.move(item.pos) if you have compound boots

he probably doesnt(item.type for the item && item part)

btw, the idea was for him to figure out the missing part, not just tell him out right.

oh sorry i thought he knew