The big ideaA variable is a named box that holds a value until a block changes it.
How it works
A game has to remember things, like how many apples you caught. It keeps each count in a variable, a box with a name.
A set block puts a value into the box. A change block adds to the value already inside.
A variable keeps its value until a block changes it. It never forgets by itself, and it never starts at zero by itself.
So a game starts with set to zero, under the flag block, to give every new game a fresh start.
How Noor's game counts.
Example 1: Counting up
The box apples starts at 0.
Each apple that lands in the basket adds one: 0 + 1 = 1, then 1 + 1 = 2, then 2 + 1 = 3.
The box shows 1, then 2, then 3.
Example 2: Set and change
The box apples holds 5.
Change apples by 1 adds one: 5 + 1 = 6.
Set apples to 0 puts a new value in, so the box holds 0.
Example 3: The box that said nine
Teo caught nine apples, and the box held 9.
Noor pressed the flag for her turn, but nobody had told the box to start again at zero.
The mix-up to fix: add set apples to 0 right under the flag block.
Example 4: Another variable
The game also has a box called lives, and the player starts with 3.
The block set lives to 3 puts a 3 in the box.
Games use variables to remember things, like apples caught or lives left.
Words to know
variable
A named box that holds a value.
set
A block that puts a value into the box.
change
A block that adds to the value in the box.
sprite
A character on the stage, like the basket.
Watch out
A variable keeps its value until a block changes it, so the old score stays unless you set it.
Set puts a value in, and change adds to what is there. They are not the same block.
The basket and the apple are sprites. They move, but they hold no number.
The flag block only starts the game. It holds no number.
Try it
The box apples holds 5. What does it hold after change apples by 1?
The box apples holds 5. What does it hold after set apples to 0?
Which block gives every new game a fresh start: set apples to 0 or change apples by 1?
Does a variable forget its value by itself?
Which one holds a number: the apples box or the basket?
Answers: 1. 6 · 2. 0 · 3. set apples to 0 · 4. No · 5. The apples box
Try at homeWrite apples on a cup and start it empty: set apples to zero. A grown-up says change, and you drop in one pebble. When they say set to zero, you empty the cup. Say how many pebbles are in the box after each step.
For grown-upsDo the Mission: write apples on a cup and start it empty, which is set apples to 0. You say change, and your child drops in one pebble. When you say set to zero, they empty the cup and say how many pebbles are in the box after each step.
Open these notes on screenScan the code, or go to tutorpip.com.