The big ideaA variable is a named box. It holds a value that can change.
How it works
A variable is a box with a name. The name is the label on the box, and the value is what sits inside.
A robot only remembers what we store, so a program keeps a number in a variable.
The name stays the same, but the value can change. That is why it is called a variable: its value can vary.
Every variable needs its own clear name, so the program can find the right box every time.
Tavi's star box.
Example 1: Name and value
Tavi's box has a label that says stars, and three stars inside.
The name is stars.
The value is 3.
Example 2: A value that changes
The box called stars holds 3.
Tavi drops in one more star: 3 + 1 = 4.
The name is still stars, and the value is now 4.
Example 3: Two boxes, one name
Mina makes a box of her own and names it stars too.
Bo opens one box and then the other, and cannot tell which is Tavi's.
The mix-up to fix: Mina renames hers moons, so every box has its own clear name.
Example 4: A clear name
A box for the number of lives could be named lives, thing or stuff.
Lives tells us what is inside.
Thing and stuff are names, but they do not say what is inside, so lives is the clearer name.
Words to know
variable
A box with a name that holds a value.
name
The label on the box. It stays the same.
value
What sits inside the box. It can change.
Watch out
The name and the value are different. Stars is the name, and 3 is the value.
Two boxes with the same name confuse the program. Give each its own name.
A name like thing or stuff works, but a clear name like coins or lives is better.
A robot does not remember a number unless it is stored in a box.
Try it
A box called coins holds 7. Is coins the name or the value?
The box stars holds 3 and Tavi drops in one more star. What is the value now?
Which is the clearer name for a box that holds lives left: lives or stuff?
Two boxes are both named stars. What is the mix-up to fix?
Can the name of a variable change when its value changes?
Answers: 1. The name · 2. 4 · 3. lives · 4. Give one a new, clear name · 5. No
Try at homeFind a small box or jar and a sticky label. Write a name on it, like stars or coins, and put a few small things inside. Count them. Take one out or add one, and say what the name is and what the value is now.
For grown-upsDo the Mission: label a small box or jar with a name such as coins, put a few small things inside, count them, then add or take one away and ask your child to say what the name is and what the value is now.
Open these notes on screenScan the code, or go to tutorpip.com.