Code Combat Computer Science 4 Level 12: Second Gem

I can’t figure out what to do. Please help.

1 Like

Hi,
could you first read the FAQ, you find it by clicking on the toolbar, the three lines at the top right corner of the main screen, then click on the FAQ.
It’s just so we can see your code, your problem and maybe even a screenshot or list of your equipment.
Thanks,
:lion: :lion: :lion:

# One gem is safe, the others are bombs.
# But you know the answer: always take the second.

while True:
    items = hero.findItems()
    # If the length of items is greater or equal to 2:
    if items <= 2:
        # Move to the second item in items
        hero.moveXY(items[1].pos.x, items[1].pos.y)
    # Else:
    else:
        # Move to the center mark.
        hero.moveXY(39, 34)

I don’t quite know what to do for “if the length of items is greater or equal to 2:”

1 Like

This is not what you have. You have:

if items <= 2:

Follow the directions and it will work.

I don’t know what to do for that part though. It says to find the length of it, but I’ve got no clue how.

1 Like

It doesn’t say to find the length. It says to write, “if the length of items is greater [than] or equal to 2”. Just write that. When you write that, the length doesn’t matter. The if conditional is true if the length is greater than or equal to 2. That’s all that matters. If this, then do that.

But what do I put for that? If I say “if length.items >= 2:” or “if items.length >=2:” then it says that length is unidentified.

1 Like

Try:

if len(items)

Then memorize this because you’re going to be seeing a ton of it.

1 Like

hello im stuck on the same level but did it right, i know this because when I sub the [1] out for another number the code works.

// One gem is safe, the others are bombs.
// But you know the answer: always take the second.

while (true) {
    var items = hero.findItems();
    // If the length of items is greater or equal to 2:
    if(items.length >= 2){
        hero.moveXY(items[1].pos.x, items[1].pos.y);
    }
        // Move to the second item in items
    // Else:
    else {
        hero.moveXY(40, 33);
    }
        // Move to the center mark.
}

Copy and paste the following, -maybe it’s the return to coordinates - hero.moveXY(40,34);

// One gem is safe, the others are bombs.
// But you know the answer: always take the second.

while (true) {
var items = hero.findItems();
//
if (items.length >= 2) {
// Move to the second item in items
hero.moveXY(items[1].pos.x, items[1].pos.y);
}
// Else:
else {
// Move to the center mark.
hero.moveXY(40, 34);
}
}

1 Like

Hi @Terry_Carstensen and welcome to the forum! :partying_face:

Can you format your code as it is described below so we will be able to help you solve this level?

Andrei

1 Like