← Back to course
Code Crew G3 / Week 03 / Monday
1/6
Week 03 Β· Conditionals

Monday

// If this, then that

Monday: Meet the Idea

Rocket stands by the door with his backpack. "Should I bring an umbrella?" he asks.

Raven looks out the window. "What do you notice about the sky?" she asks. "If it is raining, bring it. Else, leave it home."

Nova lights up. "That is a conditional," she says. "It makes a choice."

Let's finish two conditionals of our own. Each one needs an if and an else.

ROCKET asked: 'Should I bring an umbrella?' RAVEN answered: 'IF it is raining, THEN bring the umbrella. ELSE leave it home.' That is a CONDITIONAL; it makes a DECISION based on a question.

Big Idea
IF question is true β†’ do this.
ELSE β†’ do something else.

Quick Try

Finish the conditional. Write what should happen.

IF the floor is wet, THEN ____________________________
ELSE ____________________________________________

And another:

IF Mom says yes, THEN ____________________________
ELSE ____________________________________________

IF, THEN, ELSE

A conditional asks a question. The answer is TRUE or FALSE.

IF the answer is true, the THEN step runs. If it is false, the ELSE step runs.

Only one of the two steps runs each time.

IF it is raining:
    take an umbrella
ELSE:
    wear a sun hat
WHICH STEP RUNS?
  • Read the question.
  • Tap your answer.
It is raining. Which step runs?
It is sunny. Which step runs?
How many steps run each time?
Which word starts every conditional?
Rule: IF the soil is dry, THEN water the plant. ELSE wait. The soil is dry. What do you do?
Same rule. The soil is wet. What do you do?
Rule: IF the bell rings, THEN line up. ELSE keep reading. The bell rings. What do you do?
StatementTrue or false?
IF the light is green, THEN go. It is green, so you go.?
The ELSE step runs when the question is true.?
A conditional helps a program make a choice.?
The THEN step and the ELSE step both run every time.?
WHY THIS EXERCISEPrograms use conditionals to choose what to do next.
HOW NOVA RUNS AN IF
  • ?Read the question
  • ?Decide: true or false?
  • ?Pick the THEN or the ELSE path
  • ?Run that one step
WHY THIS EXERCISEEvery conditional runs the same way: ask, decide, then act.
IF the dog barks, THEN Raven looks outside. ELSE she keeps drawing. The dog is quiet. What does Raven do?
WHY THIS EXERCISEWhen the question is false, the ELSE path runs.
Try it
Make an IF rule for a game of catch.
Example: IF the ball drops, THEN take one step closer.
Play three throws and follow your rule.

Quick Check

Rule: IF the dog is hungry, THEN feed the dog. ELSE play with the dog. The dog is hungry. You ____ the dog.
Same rule. The dog is not hungry. You ____ with the dog.