- 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). You met them in the catching game in Topic 1.12. broadcast [verse v]as a cue. You met it in the Music Video.
Quick-fire
Every game so far uses the keyboard or the mouse. How can a project ask you a question? How can it wait for your answer?
Reveal the answer
One block does it. 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). This is where your typing goes.<() = ()>. It checks if the answer is right.- One script for each 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. Say something else when they are wrong.
- Run three questions in a row. Then say the score at the end.
Learnt — ask, answer, check 28 min
1 · The block that waits for a person
Every block so far runs and then finishes. This one does not. It puts a white box at the bottom of the Stage. Then it 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. 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 go away. Scratch keeps it in a block called (answer). It is two blocks below the ask block, in the same drawer.
- Tick the box beside
(answer)in the palette. - A small box shows on the Stage. It shows what you last typed.
- Run it again. Type something different. The box changes.
Putting the answer inside a sentence
say (answer) says only the word. To make a sentence, use join [apple ] [banana] from Operators. It glues two pieces together.
when flag clicked
ask [What is your name?] and wait
say (join [Hello, ] (answer)) for (3) seconds
Hello, . 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. The <() = ()> block from Operators checks it. It compares what they typed with the right answer.
- 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. Put 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 makes twenty blocks. That is too hard to read. Give each question its own small script. 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. One more script then says the score.
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
- Start a new project. Delete the cat.
- 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. Put question 3 at the bottom of the second. - Test after every 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. Get them all right once. Get them all wrong once.
My score goes up even when I am wrong.
The change-score block is under the if block, not inside it. Drag it into the gap inside the if.
Only the first question ever asks.
The broadcast at the bottom of question 1 may be missing. Or it may name a message that no script listens for. Check that 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 keeps 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 that 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 says the right score.
A question with a word answer
Your three questions probably all have number answers. Add one with a word for an answer. Then find out how fussy Scratch is about it.
- One question has a word for its right answer.
- 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” does not teach anyone anything. Make every wrong answer tell the player the right answer.
- 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. 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. It 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 for each question, joined up with broadcasts, is easy to read.
- 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
- Checks if two things are the same. Every quiz needs it.
Next lesson: three lives, a pass mark, and a show that can end before the questions run out.