Learning Goals 3 min
By the end of this lesson you will be able to:
- Use ask [] and wait to pause a script until the player types something, then read their input from the answer reporter.
- Compare the player's answer to the correct answer with () = (), and use if-then to add to a score variable only when they're right.
- Pick a final message based on the score using nested if-then-else, and read the score back to the player with the join operator.
Warm-Up — predict the ask 7 min
You met ask [] and wait back in Cluster F — but only one question at a time. Today we string five of them together. First, two predictions.
Prediction 1. Priya writes this:
when flag clicked
ask [What is 2 + 2?] and wait
ask [What colour is teh tarik?] and wait
say (answer) for (3) seconds
If Priya types 4 then brown, what does the cat say at the end?
Reveal the answer
The cat says brown. The answer reporter only ever holds the most recent answer the player typed. Priya's first answer (4) was overwritten the second she answered the second question. If you want to keep the first answer, you have to copy it into a variable before asking the next question.
Prediction 2. Daniel writes a checker:
when flag clicked
ask [What is 2 + 2?] and wait
if <(answer) = [4]> then
say [Correct!] for (2) seconds
end
What does the cat do if Daniel types four (the word, not the digit)?
Reveal the answer
The cat says nothing. Scratch compares text exactly: four is not 4. The if-then's diamond reports false and the body is skipped. For our quiz today we'll always tell players in the question whether to type a digit or a word — "Type the number, not the word" — so we don't trip them up on technicalities.
New Concept — five questions, one score 15 min
A quiz is just the same five-block pattern, five times in a row. Once you've built one question, you've built them all.
The one-question pattern
Every question in our quiz looks like this:
ask [What is 2 + 2?] and wait
if <(answer) = [4]> then
change [score v] by (1)
end
Notice the shapes:
- ask [] and wait has a square slot — text goes in.
- answer is a round reporter — a value.
- () = () is a hexagonal boolean — it fits in the if-then's diamond.
Repeat the pattern
To get five questions, stack five copies of the pattern. There's no loop here because each question has different text and a different correct answer — a loop would only help if the questions were stored in a list (which is Level 3 territory).
when flag clicked
set [score v] to (0)
ask [What is 2 + 2?] and wait
if <(answer) = [4]> then
change [score v] by (1)
end
ask [What colour is teh tarik?] and wait
if <(answer) = [brown]> then
change [score v] by (1)
end
The verdict at the end
Once all five questions are asked, the cat reads the player's score and picks one of three messages. This is a chain of if-then-else, sometimes called a cascade:
if <(score) = (5)> then
say [Excellent!] for (3) seconds
else
if <(score) > (2)> then
say [Well done!] for (3) seconds
else
say [Try again] for (3) seconds
end
end
Telling the player the number too
"Excellent!" alone is a bit thin. Add the actual score using join () () from the Operators palette — it sticks two pieces of text together:
say (join [Your score is ] (score)) for (3) seconds
score is 4, the cat says Your score is 4. The trailing space inside the brackets matters — without it you'd get Your score is4.Worked Example — building Quiz Show 15 min
Open Scratch. We'll build a five-question quiz about Malaysia. Ten steps, mostly copy-paste once you get the pattern.
Step 1 — Start a new project
New project. Keep the cat (or pick a friendlier host sprite like Giga from the library — Aljay likes Giga for quiz shows). Add a backdrop from the library — "Stage1" gives a nice studio feel.
Step 2 — Create the score variable
Variables palette → Make a Variable → name it score, "For all sprites". Tick its checkbox so the player can see their score climbing.
Step 3 — Start the script
On the host sprite drop:
when flag clicked
set [score v] to (0)
say [Welcome to Quiz Show!] for (2) seconds
Step 4 — Question 1
Add the first question and check. Stick to the pattern: ask, if-then on answer, change score.
ask [What is 2 + 2?] and wait
if <(answer) = [4]> then
change [score v] by (1)
end
Step 5 — Questions 2 and 3
Duplicate the question 1 block group (right-click the ask → Duplicate, drag onto the bottom of the stack). Change the text and the correct answer.
ask [What colour is teh tarik?] and wait
if <(answer) = [brown]> then
change [score v] by (1)
end
ask [How many states are in Malaysia? (Type the number)] and wait
if <(answer) = [13]> then
change [score v] by (1)
end
Step 6 — Questions 4 and 5
Two more, your choice of topic. Here's a maths one and a culture one to round it out:
ask [What is 7 x 8?] and wait
if <(answer) = [56]> then
change [score v] by (1)
end
ask [What is the capital city of Malaysia?] and wait
if <(answer) = [kuala lumpur]> then
change [score v] by (1)
end
Step 7 — Announce the score
After all five if-thens, tell the player their score using join:
say (join [Your score is ] (score)) for (3) seconds
Step 8 — Add the verdict cascade
Below the score-readout, drop the three-outcome cascade we saw in concept:
if <(score) = (5)> then
say [Excellent!] for (3) seconds
else
if <(score) > (2)> then
say [Well done!] for (3) seconds
else
say [Try again] for (3) seconds
end
end
Step 9 — Test it
Click the flag. Answer all five questions honestly. Confirm:
- The score counter climbs only when you're right.
- The final score-readout matches.
- The verdict matches the score band.
Step 10 — Test it the hard way
Click the flag again, but this time get every question wrong. The score should stay at 0 and you should get Try again. Then run it once more and get every question right — full 5 and an Excellent!. If both extremes work, you know the cascade is wired right.
The full assembled host script
when flag clicked
set [score v] to (0)
say [Welcome to Quiz Show!] for (2) seconds
ask [What is 2 + 2?] and wait
if <(answer) = [4]> then
change [score v] by (1)
end
ask [What colour is teh tarik?] and wait
if <(answer) = [brown]> then
change [score v] by (1)
end
ask [How many states are in Malaysia?] and wait
if <(answer) = [13]> then
change [score v] by (1)
end
ask [What is 7 x 8?] and wait
if <(answer) = [56]> then
change [score v] by (1)
end
ask [What is the capital city of Malaysia?] and wait
if <(answer) = [kuala lumpur]> then
change [score v] by (1)
end
say (join [Your score is ] (score)) for (3) seconds
What you just built: a real quiz that can be reset and replayed, gives feedback at the end, and is easy to extend by duplicating the question pattern.
Try It Yourself — three extensions 12 min
Keep your Quiz Show open. Each task changes or extends the host script.
Goal: Add immediate feedback after each question — the cat says "Correct!" for 1 second when the answer is right.
ask [What is 2 + 2?] and wait
if <(answer) = [4]> then
change [score v] by (1)
say [Correct!] for (1) seconds
end
Think: Instant feedback turns a quiz into a game. Without it, the player doesn't know they got Q2 right until the final score 30 seconds later.
Goal: Add an "or" so multiple correct answers are accepted. For "What colour is teh tarik?" both brown and tan should count.
ask [What colour is teh tarik?] and wait
if <<(answer) = [brown]> or <(answer) = [tan]>> then
change [score v] by (1)
end
Think: Real quiz writers always think about alternate correct answers. kl vs kuala lumpur is another classic one to handle with an or.
Goal: Track which question the player is on with a second variable called q. Before each question, do change [q v] by (1) and ask "Question (q): ..." using join.
when flag clicked
set [score v] to (0)
set [q v] to (0)
change [q v] by (1)
ask (join [Question ] (join (q) [: What is 2 + 2?])) and wait
if <(answer) = [4]> then
change [score v] by (1)
end
change [q v] by (1)
ask (join [Question ] (join (q) [: What colour is teh tarik?])) and wait
if <(answer) = [brown]> then
change [score v] by (1)
end
Think: Numbered questions feel more like a real quiz show. The nested join is fiddly — read it inside-out: build the "1: What is..." part first, then prepend "Question ".
Mini-Challenge — Aisyah's broken verdict 5 min
"Aisyah's quiz says Excellent for everyone"
Aisyah is upset. Her quiz ends with the cat shouting Excellent! no matter how badly she scores. She shows you her verdict:
say (join [Your score is ] (score)) for (3) seconds
if <(score) > (2)> then
say [Well done!] for (3) seconds
end
if <(score) = (5)> then
say [Excellent!] for (3) seconds
end
if <(score) < (3)> then
say [Try again] for (3) seconds
end
What does Aisyah's cat say when she scores 5/5, and how do you fix it?
Reveal the answer
The cat says Well done! then Excellent!, because 5 > 2 is true and 5 = 5 is true. Three independent if-thens don't talk to each other — each one decides on its own. The fix is to chain them with else so only one path runs:
if <(score) = (5)> then
say [Excellent!] for (3) seconds
else
if <(score) > (2)> then
say [Well done!] for (3) seconds
else
say [Try again] for (3) seconds
end
end
Same three messages, same three thresholds. But now Excellent is checked first, and the else means "only consider Well done if the player didn't already get Excellent". If-then-else is the difference between "and also" and "or instead".
Recap 3 min
You built a real quiz in one long but very repetitive script. The pattern is always the same: ask a question, compare the answer to the correct text with () = (), change the score if right. At the end, read the score back to the player with join and pick a verdict with nested if-then-else. The whole genre — every quiz, every form, every "what's your name?" intro — is built from these five blocks.
- Ask and wait
- ask [] and wait from Sensing. Pops up a text box and pauses the script until the player presses Enter. Whatever they typed lands in the answer reporter.
- Answer
- answer is a round reporter holding the player's most recent reply. It's overwritten by the next ask, so copy it into a variable if you need to keep it.
- Join
- join () () from Operators. Glues two pieces of text together. Useful for any sentence with a variable inside it — "Hello, Aisyah!", "Your score is 4".
- Cascade
- An informal name for a chain of if-then-else blocks where each else holds the next if-then. Tries conditions top-down and runs at most one branch.
- String comparison
- What () = () does when both sides are text. Exact match only —
4≠four,BROWN≠brown(in some Scratch versions).
Homework 2 min
Build Your Own Quiz. Take the in-class quiz and rebuild it with your own five questions. Pick a theme — your school, your favourite cartoon, Malaysian food, K-pop, whatever you like. Then add the polish below.
- Five new questions of your choice. At least one should be a number-answer and at least one should be a text-answer.
- Add the "Correct!" feedback from the Easy task to every question.
- Add at least one or condition (Medium task) so a question accepts two valid spellings.
- Change the verdict bands. Maybe 5 is "Genius!", 3–4 is "Not bad lah", and 0–2 is "Practice more!". Use your own words.
Save as HW-L2-44-My-Quiz.sb3. Test by playing your own quiz twice — once perfect, once all-wrong — and confirm the verdicts make sense both times.
Bring back next class:
- The
.sb3file. - Your five questions written on paper, with the correct answers marked.
- Your answer to: "Which question was hardest to phrase so the answer-check would work? Why?"
Heads up for next class: SCR-L02-45 steps back from coding entirely. We'll learn how to plan a multi-sprite project on paper before opening Scratch — the meta-skill that stops the messes you've probably hit a few times this cluster.