Beginner Coding with Blocks
Chapter
>
Level
Conditions and Decisions
Complex if statement
Objective
Collect items in the field and combine them by using condition operators.
Operators allow you to perform more complex conditions with less code. A list named stash is already set up in your initial code with five items: "milk", "grape", "strawberries", "red berries", and "empty jar". You'll use this list to learn how and and or operators work with conditions.
Once you collect all the items, head for the X marks and combine them by using the and and or logic operation blocks. Using an if block, check if items are inside the list using the find item in list block (which returns the index, or -1 if not found).
Use the find item in list block to check if an item exists in the list. If the result is greater than or equal to 0, the item is in the list. Combine this with the and and or blocks to create complex conditions.
The first condition checks if both "grape" and "empty jar" are inside the stash using the and block. If so, use the combine block with the stash variable. The second condition checks if either "strawberries" or "red berries" is present (using or) along with "milk" (using and). If the conditions are met, then the combine block is run.
Use the if block along with and and or blocks to combine items in the stash. On the top X mark, check if "grape" and "empty jar" are in the stash and combine them to make Grape Juice. On the bottom light X mark check if you have either "strawberries" or "red berries" along with "milk" and combine them to make Berry Milk.