← Back to course
Code Crew G3 / Week 03 / Thursday
4/6
Week 03 Β· Conditionals

Thursday

// If this, then that

Thursday: Traffic Light Puzzle

Rocket and Raven ride bikes to the park. A traffic light glows red. Rocket wants to zoom ahead. Then he remembers the rule and stops.

Raven nods. "What do you notice about each color?" she asks. "Each one has its own rule."

Nova blinks. "Think about a light that is broken," she says.

Let's match each color to an action. Then we'll write a tiny adventure.

What do you do at each light? Match the color to the action.

IF light is RED β†’ __________________________
IF light is YELLOW β†’ ______________________
IF light is GREEN β†’ ________________________

Tricky one

What if the light is BROKEN (not red, yellow, or green)?

Write a NEW conditional for that case.

ELSE (light is broken) β†’
Try Without Paper
Walk through your house. Make up an IF rule for one room.
Example: 'IF the lights are off in my room, THEN the day is over.'

Storyteller Mode

Write a tiny choose-your-adventure. Two choices, two endings.

You wake up and see ___________________________________.
IF you ____________________ β†’ __________________________.
ELSE you ___________________ β†’ _________________________.

A Rule for Every Case

A good conditional has a plan for every case. The ELSE catches anything you did not expect.

That is why Rocket added a rule for a broken light.

CHECK EVERY CASE
  • Read the question.
  • Tap your answer.
Rule: IF red, stop. ELSE IF green, go. ELSE wait. The light is flashing. What do you do?
Which part catches every other case?
Rule: IF the score is 10, say You win. The score is 4. What happens?
Raven wants something to happen when the score is NOT 10. What should she add?
Rule: IF you roll a 6, THEN go again. ELSE pass the die. You roll a 6. What do you do?
Same rule. You roll a 2. What do you do?
Rule: IF you land on a ladder, THEN climb up. ELSE stay. You land on a plain square. What do you do?
StatementTrue or false?
An ELSE can catch cases you did not plan for.?
A rule with no ELSE does nothing when the question is false.?
Every IF must have an ELSE IF.?
Rocket wants every case covered, even a broken light.?
WHY THIS EXERCISEThinking about every case keeps programs from surprising us.
Rule: IF the door is locked, THEN ring the bell. ELSE walk in. The door is locked. What do you do?
WHY THIS EXERCISEA true question means the THEN step runs.
Try it
Make up a rule for a hallway light.
IF it is dark, THEN turn the light on. ELSE leave it off.
Test your rule in two rooms with a grown-up.

Quick Check

Read the rule. IF the light is red, THEN stop. ELSE IF the light is green, THEN go. ELSE wait. The light is broken. What does the rule say to do? ____
WHY THIS EXERCISEELSE catches every case the IF lines did not cover. Good programs plan for the strange cases too.
← Wednesday