1 / 20
Scratch Coding · Grade 5 · Chapter 5

Scratch Conditionals: If-Then Decisions

Giving your computer programs brainpower to make decisions based on player actions.

Learning Goals

What We'll Master Today

GOAL 1

Conditionals

Master if-then and if-then-else control blocks.

GOAL 2

Sensing & Booleans

Use hexagonal Boolean blocks that ask TRUE/FALSE questions to sensors.

GOAL 3

Continuous Sensing

Nest conditionals inside forever loops to create interactive game controls.

Real-World Logic

Decisions You Make Every Day

IF you feel hungry THEN eat an apple ELSE continue playing!

Brainstorm: Name 2 decisions you made this morning that follow an "IF-THEN" rule!
Story Time

Leo's Ghostly Maze Game

Leo coded a cool knight sprite in Scratch, but when he ran the maze, the knight walked straight through all stone walls and lava pits like a ghost!

The computer didn't stop the knight because Leo never told Scratch: "IF touching wall, THEN stop moving!"
Core Concept

What is a Conditional?

A Conditional is a programming statement that checks whether a specific condition is TRUE or FALSE before running code inside it.

if <touching [Lava v]?> then {
  play sound [Ouch v] until done
  go to x: (0) y: (0) // Restart position
}
Decision Flowchart

How a Conditional Fork Works

1

Check Condition

Is touching coin? TRUE or FALSE?

2

If TRUE

Play coin chime sound, add +10 points to score.

3

If FALSE

Skip code block completely, continue script.

Scratch Blocks

Hexagonal Sensing Blocks (Booleans)

In Scratch, hexagonal blocks fit inside the diamond slot of an if block. They always return TRUE or FALSE.

<touching [Sprite v]?>

Checks if sprites collide in game physics.

<key [space v] pressed?>

Detects keyboard input from player.

<mouse down?>

Detects mouse clicks on the canvas.

Comparing Blocks

if-then vs. if-then-else

🔹 IF-THEN

Only acts when condition is TRUE. If FALSE, does nothing extra.

Example: IF touching star THEN score +1.

🔸 IF-THEN-ELSE

Gives 2 alternative branches: one for TRUE, one for FALSE!

Example: IF score > 50 THEN say "You Win!" ELSE say "Keep Trying!"

Script Structure

The Golden Secret: Nesting in Forever

An if block only checks ONCE when executed! To check continuously during a game, nest it inside a forever loop!

when green flag clicked
forever {
  if <key [right arrow v] pressed?> then {
    change x by (10)
  }
}
Side-by-Side Comparison

Dumb Motion vs. Smart Reactive Motion

❌ DUMB MOTION

Sprite moves forward blindly regardless of obstacles or walls.

✅ SMART REACTIVE MOTION

Sprite moves forward, but IF touching black wall THEN change x by (-10) to block movement!

Debunking Myths

The #1 Scratch Conditional Mistake

Student Complaint: "I pressed spacebar but my sprite didn't jump! My code is right!"
Why it failed: The student had when flag clicked ➔ if key space pressed? jump without a forever loop! Scratch checked spacebar at 0.0001s when flag was clicked, found it false, and ended!
Smartboard Voting

True or False Boolean?

Is this condition currently TRUE or FALSE?

Spot the Bug

Why Does the Door Stay Locked?

if <hasKey = 1> then [ switch costume to [OpenDoor v] ] else [ say [Door is locked!] ]
The player gets the key, but the door never switches costume when clicked!
Discussion: Where should the door check be triggered? (Hint: event block when this sprite clicked!)
Think-Pair-Share

Designing a Quiz Game in Scratch

Use the Scratch block ask [What is 5 + 5?] and wait.

Partner Activity: Write down the pseudo-code using if-then-else to check if answer = 10!
Guided Practice

Building Smooth Arrow Controls

Let's create 4-way arrow key movement together on the smartboard!

forever {
  if <key [up arrow v] pressed?> then { change y by (10) }
  if <key [down arrow v] pressed?> then { change y by (-10) }
  if <key [right arrow v] pressed?> then { change x by (10) }
  if <key [left arrow v] pressed?> then { change x by (-10) }
}
Hands-on Challenge

Chaser Game Physics

Mission: Make a Goblin sprite follow your Cat sprite. IF the Goblin touches the Cat, play a boom sound and freeze the game!
Scratch Blocks to Use: point towards [Cat v], move 3 steps, if stop [all v].
Quick Check · Question 1

What shape are Boolean conditional sensing blocks in Scratch?

ARounded Oval
BHexagon with pointed ends
CRectangle
DTriangle
Click to reveal answer
Quick Check · Question 2

Why must conditional if blocks for game controls be placed inside a forever loop?

ATo make the sprite change colors faster
BSo Scratch continuously checks for key presses throughout the entire game
CBecause Scratch will crash without it
DTo make the background music play
Click to reveal answer
Summary

Chapter 5 Key Takeaways

Looking Ahead

Next Chapter: Scratch Variables!

How do games remember high scores, player health, and countdown timers? By using Variables in Chapter 6!

Exit Ticket: Write one if-then-else rule for a video game power-up star!