Play Home Contribute GitHub Join Us Discourse Staff Members GitHub Contribution Guides Team

Code Combat Computer Science 4 Level 12: Second Gem


#1

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


#2

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:


#3
# 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:”


#4

This is not what you have. You have:

if items <= 2:

Follow the directions and it will work.


#5

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.


#6

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.


#7

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.


#8

Try:

if len(items)

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


#9

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.
}