← Back to course
Code Crew G3 / Week 03 / Wednesday
3/6
Week 03 Β· Conditionals

Wednesday

// If this, then that

Wednesday: Decision Trees

Rocket draws a tree on his tablet. It has no leaves, only questions. The first one asks about homework.

"Yes leads to free time," Raven says. "What do you notice about the no path?"

Nova shows a door and a dog. "Sometimes one if lives inside another," she says.

Let's trace the trees and build our own. Then we'll solve the door and dog puzzle.

A DECISION TREE shows IF / ELSE as a flowchart. Trace the tree below.

Did you finish your homework?
↓ DECISION ↓
YES β†’ Free time!
NO β†’ Finish the homework first

Build your own

Fill in the blanks for: SHOULD I WEAR A COAT?

Is it cold outside?
↓ DECISION ↓
YES β†’ ___________________________
NO β†’ ___________________________

And: SHOULD I PLAY OUTSIDE?

Is it raining?
↓ DECISION ↓
YES β†’ ___________________________
NO β†’ ___________________________

Nested Conditionals

Sometimes one IF lives INSIDE another IF. Read this carefully:

IF the door is open:
    IF the dog is inside:
        say 'Hi, dog!'
    ELSE:
        whistle for the dog
ELSE:
    knock on the door

Answer these

Door open, dog inside β†’ ____________________
Door open, dog NOT inside β†’ ____________________
Door closed β†’ ____________________

Inside the Nested IF

USE THE DOOR AND DOG CODE
  • Read the question.
  • Tap your answer.
The door is closed. What do you do?
The door is open. The dog is inside. What do you do?
The door is open. The dog is outside. What do you do?
When is the dog question asked?
Tree: Is it cold? YES: wear a coat. NO: wear a t-shirt. It is cold. What do you wear?
Same tree. It is warm. What do you wear?
Tree: Is it raining? YES: play inside. NO: play outside. It is dry. Where do you play?
How many arrows leave each question box in these trees?
StatementTrue or false?
A decision tree is IF and ELSE drawn as a picture.?
A nested IF is an IF inside another IF.?
The inside question is asked every single time.?
Each question box has a YES path and a NO path.?
A decision tree can only ask one question.?
WHY THIS EXERCISENested questions let a program make careful, step by step choices.
IF it is Saturday: IF it is sunny: go to the park. ELSE: build a fort. ELSE: go to school. It is a rainy Saturday. What do you do?
WHY THIS EXERCISEWith a nested IF, you answer the outside question first.

Quick Check

Look at the homework tree. Raven did not finish her homework. What does the tree tell her to do? ____
WHY THIS EXERCISEA decision tree follows one branch for each answer. Programs choose a path the same way with IF and ELSE.
← Tuesday