Variables in games
Answers are for parents and teachers.
1
Trace the secret word program for the tries sun, star and moon. What does the sprite say each time, and what is attempts at the end?
For sun: Wrong word. Try again. For star: Wrong word. Try again. For moon: The door opens! The variable attempts is 3 at the end.
2
Write the blocks for: if the score is more than 20, the sprite says Great!.
if <(score) > (20)> then, say [Great!] for (2) seconds.
3
A program sets n to 20 and then repeats until n = 0: it says n and changes n by −5. After the loop it says Go!. Write down everything that it says.
It says 20, 15, 10 and 5, and then Go!. When n reaches 0 the loop stops, so 0 is not said.
4
Design a game on paper in which a boat collects fish. Name three variables, give each a data type and say how the game ends.
Answers vary. For example: fish (integer), fuel (integer), boatName (string). The game ends when fuel is less than 1.
5
(if you have a computer or tablet) Build the countdown program in Scratch. Change the starting number and the step and check what the sprite says.
The sprite should say the numbers in order and then Go!. A step that does not divide evenly can skip over 0, so the condition should be less than 1 rather than equal to 0.