Beginner Coding with Blocks
Chapter
>
Level

Lists and Collections
Referencing list items

Objective

Grab eggs basket and check how many eggs you have inside, then place the eggs in their proper containers by referencing their position within a list.

Today's fresh batch of eggs have been collected and placed in a basket. Grab the basket and check how many eggs you have of each type so you can put them away. There are four types of eggs inside the basket: "white eggs", "dark eggs", "red eggs" and "blue eggs".

First grab the basket set by the containers and walk to the light X mark next to the table. After reaching the light X mark and facing the table, use a while loop block to check the eggs you have in the basket. Create a variable count set to 0, then use a while loop that continues while count < 4. Inside the loop, use the speak block with a text join block to combine "I have ", the value from the basket list at position count (using get item from list), " ", the value from the eggs list at position count, " in compartment ", and count. Then use the change variable by block to increase count by 1.

There are two (2) list constants contained in the basket. One list that holds the names of all four (4) eggs available to you named eggs. And another list named basket that holds how many eggs of each color the basket contains.

The basket has four (4) compartments, counted 0 - 3, eggs of each color are stored in their own compartment. This also tells you their location and order within the lists which is as follows: 0 = white eggs, 1 = dark eggs, 2 = red eggs, 3 = blue eggs.

Walk to the dark X marks next to containers and use the place block to place the correct type of egg in the right container. Each container has a sign informing you of what color egg is stored there.

You can address each type of egg in your list by identifying where in the list they are located using the get item from list block. Connect the list variable (basket) and the index number (0, 1, 2, or 3) to access a specific value within the list.

Walk to all four dark X marks and place the eggs of each corresponding type in their proper location. For example: use get item from list with basket and index 0, then connect it to the place block on the dark X mark with the white eggs sign. Reference the numbered chart above, use it in combination with place and get item from list on all four dark X marks to complete the level.

Code book