Hello! Welcome to the lesson on Conditionals with the Lunch Robot. This lesson is all about learning how to make decisions in coding, like saying 'if this happens, then do that'. We'll look at fun examples, draw flowcharts, and even pretend to be a robot that decides what to serve for lunch based on rules. Get ready for some exciting activities!
Ask the students if they've ever had to make a decision based on something else happening."
Examples:
"If it's sunny, then I'll play outside."
"If the bus is late, then I'll walk to school."
Explain that these are called "conditional statements." The word "conditional" means something depends on a condition being true.
In coding, we use conditional statements to tell a computer what to do based on different situations. The most basic one is the "if... then..." statement.
Display the following Flowchart:
Explain that the computer is a "robot" that can only follow very specific instructions.
We have to give it instructions for every possible outcome.
Point out that this flowchart in the previous step only gives us one set of instructions if the condition is true.
What if we want the computer to do something different if the condition is not true?
In coding, when we want to give our robot an instruction for what to do if the condition is false, we use the word else."
Think of it like giving a plan B! The robot will always have an instruction, no matter what!
Look at this new flowchart that incorporates an 'Else' feature.
Work with the students to create their own if... then... else... examples based on the new structure:
"If it's sunny, then we play outside. Else, we play inside."
"If the shop has orange juice, then I'll get orange juice, else, I'll get a water!"
Explain to the students that we are going to a 'Lunch Ordering Robot.' This robot's job is to figure out what to serve for lunch, but it needs very specific rules to follow. The rules are based on what's available."
Establish the Rules (The Conditions): On the whiteboard, display the following list of "Rules" for the robot:
then
serve soup.(You may want to write these on a whiteboard/display chart so they can remain in sight for the lesson.)
Introduce the Scenario: Explain to the students that they will work in small groups and pretend to be a "Lunch Robot." Their job is to follow the rules on the board precisely to create the day's menu.