Learning Goals 3 min
By the end of this lesson you will be able to:
- Find and name the three comparison operator blocks — () < (), () = (), () > () — in the green Operators palette.
- Build a comparison by dropping numbers, variables, and round reporters (like x position) into the two slots.
- Nest a comparison inside the diamond slot of if <> then or if <> then else to ask sharp, specific questions about the game world.
Warm-Up — three quick predictions 7 min
Three tiny puzzles. Each one is a hexagonal comparison. Without opening Scratch, decide whether each one reports true or false.
1. What does this report?
<(7) > (3)>
Reveal
True. 7 is bigger than 3. The block lights up green to show it's true.
2. What about this?
<(5) = (5)>
Reveal
True. 5 equals 5. The = here is a question — "are these equal?" — not a command. It's very different from set [score v] to ().
3. The tricky one. Aisyah's score is exactly 10. Is this true or false?
<(score) > (10)>
Reveal
False. The block is "is score strictly bigger than 10?". Score is 10, which is equal to, not bigger than. To be true, the score would need to be 11 or higher. There is no "greater-or-equal" block in Scratch — you have to write the question carefully.
Today's lesson is the three blocks behind every question like these. After this lesson you'll be able to write hexagons of your own, instead of borrowing the ready-made ones from Sensing.
New Concept — the three comparison operators 15 min
Open the green Operators palette. Scroll a little. You'll see three blocks that are shaped like hexagons with two round slots each:
<() < ()>
<() = ()>
<() > ()>
What goes in the slots
The two round slots accept anything that is or reports a number:
- A literal number — just type
10into the slot. - A variable — drag in score or lives.
- A round reporter — x position, y position, direction, size, timer, loudness, and many more.
- Another operator — even () + () can go in a slot, so you can ask "is
x + 10 > 200?".
The three operators, one at a time
() < () — strictly less than
Reports true if the left number is smaller than the right. Examples:
<(3) < (7)>
<(lives) < (1)>
<(y position) < (-100)>
() = () — equal to
Reports true if the two numbers are exactly equal. Numbers must match — 10 equals 10, but 10 does not equal 10.5.
<(score) = (0)>
<(lives) = (3)>
<(direction) = (90)>
Important: the = here asks a question. It does not set anything. The block that sets is set [score v] to (), and it lives in the orange Variables palette. They look similar in English but they're completely different blocks.
() > () — strictly greater than
Reports true if the left number is bigger than the right.
<(score) > (10)>
<(x position) > (0)>
<(timer) > (30)>
The "strictly" trap
Both () < () and () > () are strict. They report false when the numbers are equal. Scratch does not have a "less-or-equal" or "greater-or-equal" block — there's no <=, no >=.
If you want "score is at least 10" (10 counts as winning), you can't write (score) > (10) — that would need 11 to be true. You write (score) > (9) instead, or you check (score) = (10) with a separate if-then. Picking the right comparison is half the battle.
Putting it in a diamond
Comparison operators are hexagons. They fit into any diamond slot — in if-then, if-then-else, or wait-until:
when flag clicked
forever
if <(score) > (10)> then
say [You won!] for (2) seconds
stop [all v]
end
end
Worked Example — the seeker measures real distance 12 min
Back to Hot or Cold. So far "closeness" was a rough left/right guess. Today the seeker gets a real ruler. We add a hidden treasure sprite and compare the live distance with thresholds. Eight steps.
Step 1 — Open the project and add a treasure
Open your Hot or Cold project. Add a small sprite from the library — a Star works well. Rename it treasure.
Step 2 — Park and hide the treasure
On the treasure: when ⚑ clicked + go to x: (120) y: (-20) + hide. The treasure sits silently out of view.
Step 3 — Meet the distance reporter
Click the seeker. Open the light-blue Sensing palette. Find the round reporter distance to [ v]. Click its dropdown and pick treasure:
(distance to [treasure v])
This block reports a number — like 23, 147.5, or 300. A small number means close. A big number means far. It is round, not a hexagon — so we must wrap it in a comparison to ask a yes/no question.
Step 4 — The seeker follows the mouse
On the seeker: when ⚑ clicked + forever + inside it go to [mouse-pointer v]. Now you drive the seeker with your mouse.
Step 5 — Is it HOT? (distance < 60)
Inside the forever, below the go-to, add if <> then. In the diamond drop () < () with distance to [treasure v] on the left and 60 on the right. Inside: say [HOT!] for (0.5) seconds.
Step 6 — Is it warm? (distance < 150)
Add a second if <> then below the first. Diamond: () < () with distance to [treasure v] and 150. Inside: say [Warmer!] for (0.5) seconds.
Step 7 — The full assembled seeker stack
when flag clicked
forever
go to [mouse-pointer v]
if <(distance to [treasure v]) < (60)> then
say [HOT!] for (0.5) seconds
end
if <(distance to [treasure v]) < (150)> then
say [Warmer!] for (0.5) seconds
end
end
Step 8 — Click the flag and hunt
Drag your mouse toward the hidden treasure. As you cross 150 pixels it says "Warmer!". Cross 60 pixels and it adds "HOT!". The closer the smaller the number — closeness is now honest.
What you just built: the entire pattern of game logic — read a number, compare it to a target, react. The single distance to [treasure v] reporter is the true engine of Hot or Cold. Next lesson we tidy these tests with clean booleans.
Try It Yourself — three comparison drills 15 min
Goal: Make the cat say Above! whenever its y-position is greater than 0, and Below. otherwise. Drag the cat around with your mouse to test.
when flag clicked
forever
if <(y position) > (0)> then
say [Above!]
else
say [Below.]
end
end
Think: What happens exactly at y = 0? The else branch runs — because 0 > 0 is false. The cat says "Below." even though it's smack in the middle.
Goal: Make a cat that hops between sizes based on its x-position. If x < -100, size 50 (small). If x > 100, size 150 (big). Otherwise, size 100. You'll need two if-then-elses, or three if-thens.
when flag clicked
forever
if <(x position) < (-100)> then
set size to (50) %
else
if <(x position) > (100)> then
set size to (150) %
else
set size to (100) %
end
end
end
Think: Nesting lets you handle three-way splits with two comparisons. This is the same pattern you'd use for "small / medium / large", "easy / medium / hard", or any three-bucket sort.
Goal: Build the "Goldilocks" sprite — it likes its porridge temperature exactly 7. Make a variable temp. The sprite should say Too cold! if temp < 7, Too hot! if temp > 7, and Just right! if temp = 7. Press the up arrow to add 1 to temp, down arrow to subtract 1.
when flag clicked
set [temp v] to (5)
forever
if <(temp) < (7)> then
say [Too cold!]
end
if <(temp) > (7)> then
say [Too hot!]
end
if <(temp) = (7)> then
say [Just right!]
end
end
when [up arrow v] key pressed
change [temp v] by (1)
when [down arrow v] key pressed
change [temp v] by (-1)
Think: The three comparisons together cover every possible value of temp. Mathematicians call this exhaustive — no matter what the variable is, exactly one branch fires. That's a guarantee you set up by choosing your operators carefully.
Mini-Challenge — Daniel's broken win 5 min
"It says I won when I have zero points"
Daniel is building a click-to-score game in KL. He wants the cat to say You win! when the score reaches 10. He writes:
when flag clicked
set [score v] to (0)
forever
if <(10) > (score)> then
say [You win!] for (1) seconds
end
end
What did Daniel mean to write, and what is the question he actually wrote?
Reveal one valid solution
Daniel wrote (10) > (score) — read aloud, that's "is 10 bigger than score?". With score at 0, 10 is bigger than 0, so it's true, and the cat shouts immediately. Daniel had his slots backwards.
He wanted "is score bigger than 10?" — the variable on the left:
when flag clicked
set [score v] to (0)
forever
if <(score) > (10)> then
say [You win!] for (1) seconds
end
end
Same blocks, same numbers — slots swapped. The fix is one drag.
(Bonus catch: even the fixed version needs score to reach 11 to win, because > is strict. If Daniel wants "10 or more counts as winning", he should write (score) > (9) — a tiny number trick that earns him the off-by-one fix.)
Always read your comparison aloud before you trust it. "Score is bigger than ten" is correct. "Ten is bigger than score" is the opposite question.
Recap 3 min
You met the three comparison operators in the green Operators palette: () < (), () = (), and () > (). Each takes two numbers and reports a hexagonal true-or-false answer. The hexagonal shape means they slot into any diamond — if-then, if-then-else, wait-until. Scratch's = is a question, not an assignment; its < and > are strict (no "or equal" version exists). Pick the right operator and put the variable on the correct side — read your comparison aloud to check.
- Comparison operator
- A green Operators block that takes two numbers and reports whether they relate in a particular way (less, equal, greater). Always reports a boolean.
- Strict
- Both () < () and () > () are strict — they report false when the two numbers are equal. There is no greater-or-equal in Scratch.
- Slot
- The two round holes in a comparison block. Accepts numbers, variables, or other round reporters.
- Assignment vs. comparison
- The orange set [v v] to () sets a variable. The green () = () asks whether two values are equal. They both use "=" in English but they are completely different blocks.
- Exhaustive
- A set of comparisons that together cover every possible value.
x < 7,x = 7, andx > 7are exhaustive — for any number x, exactly one is true.
Homework 2 min
The Comparison Triple. Build one project with one cat that uses each of the three comparison operators at least once, all reading from the same variable.
- Make a variable called
energy. Set it to 50 at the flag. - Add two key controls: up arrow does change [energy v] by (5), down arrow does change [energy v] by (-5).
- In a forever loop on the cat:
— if (energy) < (20), set colour effect to 0 and sayTired....
— if (energy) = (50), set colour effect to 0 and sayJust normal..
— if (energy) > (80), set colour effect to 100 and sayWide awake!. - Each of the three if-thens uses one of the three operators. Don't use an else — leave silent gaps for energy values in between, then notice the cat goes quiet.
Save as HW-L2-08-Energy.sb3. Press the arrows to nudge energy up and down. Watch the cat react at the three threshold values.
Bring back next class:
- The
.sb3file. - Your answer to: "What values of
energymake the cat go silent — i.e., none of the three if-thens fire? List at least three."
Heads up for next class: SCR-L02-09 zooms out and looks at the hexagonal shape itself — booleans as a category. You'll see that comparisons, sensing questions, and the "and / or / not" operators all share the same hexagon for a reason.