Lesson 2: A box with a name
Unit overview - Previous: Lesson 1 - Next: Lesson 3
About 45 minutes.
Goal
Children learn that a variable is like a box with a name that holds one
value at a time. They run and trace programs that use SET, CHANGE ... BY
and SAY, and say the final value.
Materials
- One "score" box per group of four, with a label.
- One set of number cards 0 to 20 per group.
- Program cards A to D (below), on cards or the board.
- A class trace table on the board (columns: step, score).
- Paper and pencils for traces and for writing a program in Part 3.
Steps
Opening (5 min)
- Show the empty "score" box. Ask: "In a game, how does the game remember
your score?" (Take ideas.)
- Say: "Programs keep things to remember in a variable. Think of it as
a box with a name on it. The box holds one number at a time."
- Put the 0 card in the box. "The value of score is now 0."
Main activity (30 min)
Part 1: three cards (8 min). Teach the three cards:
SET score TO 0: take out whatever card is in the box and put in the 0
card.
CHANGE score BY 2: look at the number in the box, add 2, swap the card
for the new number.
SAY score: read the number in the box aloud (or hold it up).
Model Program A with the class, filling in the trace table:
SET score TO 0
CHANGE score BY 1
CHANGE score BY 1
SAY score
| Step |
score |
| SET score TO 0 |
0 |
| CHANGE score BY 1 |
1 |
| CHANGE score BY 1 |
2 |
| SAY score |
2 (said aloud) |
Part 2: groups run programs (14 min). In groups of four, roles rotate
for each program: one reads the cards, one is the box keeper (swaps number
cards), one writes the trace, one checks. Each group runs:
- Program B:
SET score TO 5, CHANGE score BY 2, CHANGE score BY 3,
SAY score. (5, 7, 10; says 10.)
- Program C:
SET score TO 3, SET score TO 7, SAY score. (3, then 7;
says 7. SET replaces the old value; it does not add.)
Then Program D, with a term 1 loop:
SET score TO 0
REPEAT 4 TIMES:
CHANGE score BY 2
SAY score
(0, 2, 4, 6, 8; says 8.)
Part 3: one box, one value (8 min). Ask groups: "After Program C, where
did the 3 go?" (It was taken out; the box only holds the newest value.) Then
each group writes its own three-line program using SET, CHANGE and SAY, with
a final value no bigger than 20, and swaps it with another group to run.
The writers check the answer.
Discussion questions (with answers) (5 min)
- "How is SET different from CHANGE?" (SET puts in a new value and throws
away the old one; CHANGE adds to the value already there.)
- "Why does the box have a name?" (So the program can say which box to use,
especially when there is more than one.)
- "Can the box hold two numbers at once?" (No. One value at a time.)
Closing check (with answers) (5 min)
Children write the number that is said.
SET score TO 4, CHANGE score BY 3, SAY score. (7)
SET score TO 2, REPEAT 3 TIMES: CHANGE score BY 5, SAY score. (17)
SET score TO 9, SET score TO 1, CHANGE score BY 1, SAY score. (2)
Vocabulary
variable, value, set, change, trace
Differentiation
- Support: Use the box and number cards for every step; keep values
under 10. A partner reads the cards aloud.
- Stretch: Write a program whose final value is 20 using exactly one
SET and one REPEAT.
- Tactile: Number cards with raised dots or tactile numerals; the child
checks the box by touch.
Safety
- No special risks. Keep boxes and cards on desks.
Teacher notes and misconceptions
- The most common mistake is treating SET like CHANGE (answering 10 for
Program C). Act it out: take the 3 card out of the box, put the 7 in.
- Some children write every value in the box at once, like a list. Keep
only one card in the box.
- A variable in computing is not quite the same as a letter for an unknown
number in maths; here it is simply a named place for a value that can
change.