Variables in Scratch
Answers are for parents and teachers.
1
Use the tickets program (price 4). What does the sprite say if the user types 2, 5 and 10?
2 × 4 = 8, so Total: 8. 5 × 4 = 20, so Total: 20. 10 × 4 = 40, so Total: 40.
2
Write the blocks, in order, for a program that asks ‘What is your favourite number?’, stores the reply in a variable called favourite and then says the number times 2.
when this sprite clicked, ask [What is your favourite number?] and wait, set [favourite v] to (answer), say ((favourite) * (2)) for (2) seconds. For 7 the sprite says 14.
3
The tickets program (price 4) should say ‘Total: 12’ when the user types 3, but it says ‘Total: 7’. What is the bug and how do you fix it?
The set total block adds instead of multiplying: (tickets) + (price) gives 3 + 4 = 7. Change it to ((tickets) * (price)), which gives 3 × 4 = 12.
4
Draw a flowchart for a program that uses three variables: name, fish and cost. It asks for a name, asks how many fish, and then sets cost to fish × 3 and says the name and the cost.
Start, ask for the name, set name to the answer, ask how many fish, set fish to the answer, set cost to fish × 3, say name and cost, stop. The variables are name (string), fish (integer) and cost (integer).
5
(if you have a computer or tablet) Build the tickets program in Scratch with the monitors on. Click the flag, then the sprite, and watch the three monitors.
After the flag the monitors show 0, 4 and 0. After typing a number the tickets and total monitors change and the price stays at 4.