- Learnt28 min · maths blocks, pick random, join, checking
- Basic25 min · a five-question round
- Challenge 1–327 min · the sevens, an adding round, a missing number
- Extrabonus · the player picks how many
Review — the Monster Maker 5 min
The Monster Maker is finished. Three things from it come back today.
- Each part was a costume.
(costume [number v])told us which one it wore. change [color v] effect by (25)changed a part without a new costume.go to [front v] layerput a part on top of the others.
Quick-fire
The random-monster button chose a head for you. Which block let the program choose?
Reveal the answer
(pick random (1) to (6)), dropped into switch costume to [costume1 v]. The program picked a number, not you. Today it picks numbers for a maths question.
Today’s Topic 3 min
((3) * (4)),((3) + (4))and((9) - (4))— Scratch does the sums(pick random (1) to (10))— numbers nobody chose(join (a) (join [ × ] (b)))— a question made of numbers<(answer) = ((a) * (b))>— Scratch checks the answer
Learning outcome
By the end of this lesson you will be able to:
- Use the green maths blocks to work out a number.
- Make a new question every time with pick random and join.
- Check a typed answer, and give the right one when it is wrong.
Learnt — a question nobody wrote 28 min
1 · Scratch can do sums
In Level 1 your quiz knew one answer. You typed it in yourself. Today Scratch works the answer out.
- Click Operators. It is the green drawer.
- Drag out
(() * ())into the Script Area. - Click the left circle and type 7. Click the right circle and type 8.
- Click the block itself, not the circles.
- A small bubble pops up under it. It says 56.
((7) + (8))
((15) - (8))
((7) * (8))
These round blocks report a number. So you can drop one into any round hole — a say block, a set block, even another green block.
when flag clicked
say ((7) * (8)) for (2) seconds
say ((7) + (8)) for (2) seconds
say ((15) - (8)) for (2) seconds
How to use this: Click the green flag to start it. Nothing else to press — watch it through, then use ↺ Reset to run it again.
2 · Numbers nobody chose
A quiz with the same question every time is boring. Let the program pick the numbers.
We need somewhere to keep them, so we make two variables. In maths the two numbers are often called a and b, so we use those names.
- Click Variables, then Make a Variable.
- Type
a, keep For all sprites, press OK. - Do it again for
b. - Drag out
set [a v] to (0). - Drop
(pick random (1) to (10))from Operators into its circle. - Do the same with a second set block for b.
set [a v] to (pick random (1) to (10))
set [b v] to (pick random (1) to (10))
3 · Glue the question together
The question has three pieces: a, the sign, and b. The (join [apple ] [banana]) block only glues two. So we put a join inside a join.
- Drag a
(join [apple ] [banana])into the Script Area. - Drag a second join into its right-hand hole.
- Drop
(a)into the first hole. - In the middle hole type a space, then ×, then a space.
- Drop
(b)into the last hole.
say (join (a) (join [ × ] (b))) for (2) seconds
Put it all in a loop, and the Wizard makes up five questions by himself.
when flag clicked
repeat (5)
set [a v] to (pick random (1) to (10))
set [b v] to (pick random (1) to (10))
say (join (a) (join [ × ] (b))) for (2) seconds
say (join [The answer is ] ((a) * (b))) for (2) seconds
end
How to use this: Click the green flag to start it. Nothing else to press — watch it through, then use ↺ Reset to run it again.
4 · Scratch checks the answer
Now the Wizard asks instead of says. You met ask [What's your name?] and wait in the Quiz Show. The question goes in its white hole, and the join fits there too.
To check, compare (answer) with ((a) * (b)). You never type the right answer in. Scratch works it out every time.
when flag clicked
set [a v] to (pick random (1) to (10))
set [b v] to (pick random (1) to (10))
ask (join (a) (join [ × ] (b))) and wait
if <(answer) = ((a) * (b))> then
say [Correct!] for (2) seconds
else
say (join [Not quite. The answer is ] ((a) * (b))) for (3) seconds
end
How to use this: Click the green flag, then type your answer in the box and press Enter.
Why do we need a and b at all?
Why not put pick random straight into the question? Try it. It goes wrong in a sneaky way.
ask (join (pick random (1) to (10)) (join [ × ] (pick random (1) to (10)))) and wait
if <(answer) = ((pick random (1) to (10)) * (pick random (1) to (10)))> then
say [Correct!] for (2) seconds
end
A variable remembers the number. The question and the check both read the same a and the same b, so they always agree.
Basic — a five-question round 25 min
Build one question and test it. Only then wrap it in a loop.
Step 1 — the room
- Start a new project and delete the cat.
- Choose the Chalkboard backdrop.
- Add the Wizard sprite. Drag him to the left of the board.
Step 2 — three variables
- Make
score,aandb, all For all sprites. - Leave score ticked, so it shows on the Stage.
- Untick a and b if you like. The game still works.
Step 3 — one question
- On the Wizard, start with
when flag clicked. - Add the two set blocks with pick random.
- Add the ask block with the join inside it.
- Add an if / else with
<(answer) = ((a) * (b))>. - Press the flag. Answer right once, then wrong once.
Step 4 — five questions
- Wrap everything under the hat in
repeat (5). - Above the repeat, add
set [score v] to (0). - In the top half of the if, add
change [score v] by (1).
Step 5 — the score
- Under the repeat, add a say block.
- Build the sentence with a join inside a join.
- Play the whole round twice. Once well, once badly.
when flag clicked
set [score v] to (0)
repeat (5)
set [a v] to (pick random (1) to (10))
set [b v] to (pick random (1) to (10))
ask (join (a) (join [ × ] (b))) and wait
if <(answer) = ((a) * (b))> then
change [score v] by (1)
say [Correct!] for (1) seconds
else
say (join [Not quite. It is ] ((a) * (b))) for (2) seconds
end
end
say (join [You scored ] (join (score) [ out of 5])) for (4) seconds
How to use this: Click the green flag, then type your answer in the box and press Enter. Do it five times.
It says “Not quite” when I was right.
Look inside the check. It must use (a) and (b), not new pick random blocks.
Every question is the same.
Your two set blocks are above the repeat. Move them inside it, so they run every time round.
The question reads “7×8” with no gaps.
The middle hole of the join needs a space, then ×, then a space.
My score goes up even when I am wrong.
The change block is under the if, not inside it. Drag it into the top half.
The sevens
Practise one times table only — the 7 times table.
- Every question starts with 7.
- The other number goes from 1 to 12.
- Ten questions, and the score says “out of 10”.
How to use this: Click the green flag, then type your answer in the box and press Enter.
Teacher reveal — one number stops being random
when flag clicked
set [score v] to (0)
set [a v] to (7)
repeat (10)
set [b v] to (pick random (1) to (12))
ask (join (a) (join [ × ] (b))) and wait
if <(answer) = ((a) * (b))> then
change [score v] by (1)
say [Correct!] for (1) seconds
else
say (join [Not quite. It is ] ((a) * (b))) for (2) seconds
end
end
say (join [You scored ] (join (score) [ out of 10])) for (4) seconds
Some will type 7 straight into the join and the check. That works too. Ask them which version makes the 8 times table a one-number change.
An adding round
Turn your round into a plus round, with bigger numbers.
- Both numbers go from 10 to 50.
- The question shows a + sign.
- A wrong answer still shows the right sum.
Teacher note — three places must agree
The sign lives in three places: the join in the ask, the check, and the join in the else. Most pupils change the first and forget one of the others. The game still runs, and marks every right answer wrong.
set [a v] to (pick random (10) to (50))
set [b v] to (pick random (10) to (50))
ask (join (a) (join [ + ] (b))) and wait
if <(answer) = ((a) + (b))> then
change [score v] by (1)
else
say (join [Not quite. It is ] ((a) + (b))) for (2) seconds
end
Next lesson the right answer goes into its own variable, so it lives in one place.
The missing number
Turn the question around. Show the answer, and hide one of the numbers.
- The question looks like “6 × ? = 42”.
- Scratch works out the 42 by itself.
- The player types the missing number.
- A wrong answer says what the missing number was.
How to use this: Click the green flag, then type your answer in the box and press Enter.
Teacher reveal — the check changes, not just the words
set [a v] to (pick random (2) to (10))
set [b v] to (pick random (2) to (10))
ask (join (a) (join [ × ? = ] ((a) * (b)))) and wait
if <(answer) = (b)> then
change [score v] by (1)
say [Correct!] for (1) seconds
else
say (join [The missing number was ] (b)) for (2) seconds
end
The times block moves from the check into the question. The check becomes plain (b). Starting from 2 avoids “1 × ? = 5”, which feels like a trick.
You choose how many
Before the first question, ask the player how many questions they want.
- The round asks exactly that many questions.
- The last line says “out of” that number.
- It works for 3, and it works for 12.
Teacher reveal
when flag clicked
ask [How many questions?] and wait
set [rounds v] to (answer)
set [score v] to (0)
repeat (rounds)
set [a v] to (pick random (1) to (10))
set [b v] to (pick random (1) to (10))
ask (join (a) (join [ × ] (b))) and wait
if <(answer) = ((a) * (b))> then
change [score v] by (1)
end
end
say (join [You scored ] (join (score) (join [ out of ] (rounds)))) for (4) seconds
A variable fits in the repeat’s hole. Many pupils do not know that until they try. The three joins at the end are the hard part — build the inside one first.
Summary 4 min
Today the program stopped needing you to write its questions.
- The green blocks
((a) + (b)),((a) - (b))and((a) * (b))do the sums. (pick random (1) to (10)), kept in a variable, makes a new question each time.- A join inside a join glues numbers and signs into one question.
<(answer) = ((a) * (b))>checks the answer with the same numbers the question used.
- Reporter
- A round block that gives back a number or a word.
- Random
- Picked by the computer. You cannot guess it.
- Join
- Glues two pieces of writing into one.
- Operator
- A green block that does maths or compares things.
Next lesson: sixty seconds on the clock, three lives, and a round that ends by itself.