- Learnt28 min · ask, answer, and telling right from wrong
- Basic25 min · build a three-question show
- Challenge 1–327 min · your questions, a word answer, a helpful reply
- Extrabonus · a host who remembers your name
Review — where we got to 5 min
The Maze Escape is finished. Two things come back today.
- A
scorevariable, andchange [score v] by (1), from the catching game in Topic 1.12. broadcast [verse v]as a cue, from the Music Video.
Quick-fire
Every game so far reads the keyboard or the mouse. How would a project ask you a question and wait for a proper answer?
Reveal the answer
There is one block for it, and it is in Sensing. It is the only block in Scratch that stops everything and waits for a person.
Today’s Topic 3 min
ask [What is your name?] and wait— the project waits for you(answer)— where your typing goes<() = ()>— checking whether the answer is right- One script per question, joined up with broadcasts
Learning outcome
By the end of this lesson you will be able to:
- Ask a question and use what the player types.
- Say one thing when they are right and a different thing when they are wrong.
- Run three questions in a row and read the score out at the end.
Learnt — ask, answer, check 28 min
1 · The block that waits for a person
Every block so far has run and finished. This one does not. It puts a white box at the bottom of the Stage and waits.
- Click Sensing. It is the light blue drawer.
- Drag out
ask [What's your name?] and wait. - Click the white box in the block and type your own question.
- Press the green flag.
- A box appears at the bottom of the Stage. Type something and press Enter.
What you typed did not disappear. Scratch kept it in a block called (answer), two blocks below the ask block in the same drawer.
- Tick the box beside
(answer)in the palette. - A small box appears on the Stage showing what you last typed.
- Run it again and type something different. The box changes.
Putting the answer inside a sentence
say (answer) says only the word. To make a sentence, glue two pieces together with join [apple ] [banana] from Operators.
when flag clicked
ask [What is your name?] and wait
say (join [Hello, ] (answer)) for (3) seconds
Hello, matters — without it the host says “Hello,Mia”.How to use this: Click the green flag, then type your answer in the box and press Enter.
2 · Right or wrong
A quiz has to know the right answer. You compare what they typed with what it should be, using the <() = ()> block from Operators.
- Drag
if <> thenwith itselsehalf out of Control. - Drop
<() = ()>into its diamond. - Drag
(answer)into the left side. - Type the right answer into the right side.
- Put a happy say block in the top gap and a kind one in the bottom gap.
when flag clicked
ask [How many legs has a spider?] and wait
if <(answer) = [8]> then
say [Correct!] for (2) seconds
else
say [No. A spider has 8.] for (2) seconds
end
How to use this: Click the green flag, then type your answer in the box and press Enter.
3 · Three questions without a giant stack
Three questions in one stack is twenty blocks. Nobody can read that. Give every question its own little script, and let each one call the next.
when I receive [question 1 v]
ask [How many legs has a spider?] and wait
if <(answer) = [8]> then
change [score v] by (1)
end
broadcast [question 2 v]
The last question broadcasts result instead, and one more script reads the score out.
when I receive [result v]
say (join [You scored ] (join (score) [ out of 3.])) for (4) seconds
How to use this: Click the green flag, then type your answer in the box and press Enter.
Basic — build the show 25 min
Build one question and test it. Only then build the second one.
Step 1 — the room
- New project, cat deleted.
- Choose the Theater backdrop.
- Add a person sprite as the host. Avery works well.
- Add a Microphone sprite beside them if you like.
Step 2 — the score
- In Variables, make a variable called
score. - Leave its box ticked so it shows on the Stage.
- On the host, start a stack:
when flag clicked, thenset [score v] to (0).
Step 3 — the first question
- Add
broadcast [question 1 v]under the set block. Scratch will ask you for a new message name. - Start a new stack with
when I receive [question 1 v]. - Put the ask block, the if block and the change-score block in it.
- Test it. Answer right, and watch the score go to 1. Answer wrong, and it stays 0.
Step 4 — the other two
- Right-click your question script and choose Duplicate. Twice.
- Change the hat on each copy to question 2 and question 3.
- Change the question and the right answer in each one.
- Put
broadcast [question 2 v]at the bottom of the first one, and question 3 at the bottom of the second. - Test after every single change.
Step 5 — the result
- At the bottom of question 3, broadcast
result. - Build the
when I receive [result v]script with the joined sentence in it. - Play the whole show twice. Once perfectly, once badly.
My score goes up even when I am wrong.
The change-score block is under the if block instead of inside it. Drag it into the mouth of the if.
Only the first question ever asks.
The broadcast at the bottom of question 1 is missing, or it names a message no script is listening for. Check the dropdown says exactly question 2.
The score keeps going up between runs.
set [score v] to (0) is missing from the green-flag stack. A variable remembers its value until something sets it.
My right answer is marked wrong.
Look for a space. 8 and 8 are different to Scratch. Also check you did not type the answer into the ask block by mistake.
Your own three questions
Throw my questions away. Write three of your own about anything you like.
- Three questions, all yours.
- Each one adds a point when it is right.
- The result at the end still reads out the correct score.
A question with a word answer
All three of your questions probably want a number. Add one whose answer is a word, and find out how fussy Scratch is about it.
- One question whose right answer is a word.
- You have tried it with a capital letter and without.
- You have tried it with a space on the end.
- You can say which of those Scratch accepts.
Teacher note — what to let them discover
Scratch ignores capital letters and does not ignore spaces. Let them find both by typing rather than being told. The child who types a trailing space and sees a correct answer marked wrong has learnt something no explanation delivers as well.
Say what the right answer was
“Wrong” teaches nobody anything. Make every wrong answer tell the player what they should have said.
- All three questions have an else branch.
- Each else branch names the correct answer.
- It sounds kind, not cross.
A host who remembers your name
Ask the player their name before the first question, and use it again on the result card at the end.
How to use this: Click the green flag, then type your answer in the box and press Enter.
- The host greets the player by name before question 1.
- The result card says the player’s name and their score.
- It still works if the next player types a different name.
Teacher notes — the trap this mission is built on
(answer) only holds the latest reply. By the time the show ends, the name has been overwritten by the last question’s answer. The name has to be copied into a variable of its own the moment it arrives.
when flag clicked
ask [What is your name?] and wait
set [player v] to (answer)
say (join [Good luck, ] (player)) for (2) seconds
broadcast [question 1 v]
Then the result card can use it, however many questions have been asked since.
when I receive [result v]
say (join (player) (join [ scored ] (score))) for (4) seconds
Most pupils will try say (answer) at the end first and be surprised. Let them. It is the fastest way to understand what a variable is FOR.
Going further: next lesson a wrong answer starts costing something.
Summary 4 min
Today the project stopped talking at the player and started listening to them.
ask [] and waitstops everything until a person types.- What they typed is waiting in
(answer). <() = ()>inside an if / else tells right from wrong.- One script per question, joined up with broadcasts, stays readable.
- Ask
- A block that stops the project and waits for the player to type something.
- Answer
- Where Scratch keeps the last thing the player typed. Only the last one.
- Join
- Glues two pieces of writing together to make one sentence.
- Equals
- Asks whether two things are the same. The heart of every quiz.
Next lesson: three lives, a pass mark, and a show that can end before the questions run out.