Memory Box
Variables: Named boxes that hold values
Year 7 Computer Science
Live Demo Setup
Three volunteers each hold a variable card:
When an event changes your variable — cross out the old value and write the new one!
Event: Treasure Chest!
GOLD = GOLD + 20
What was GOLD? 0
0 + 20 = 20
GOLD is now 20
Volunteer 2: update your card!
Event: Goblin Attack!
HEALTH = HEALTH - 3
What was HEALTH? 10
10 - 3 = 7
HEALTH is now 7
Volunteer 1: update your card!
The Rule
The NAME stays fixed — it never changes.
The VALUE can change at any time.
Think of it as a labelled box:
- The label (name) is permanent
- The contents (value) can be replaced
Your Turn — Trace the Adventure
Take the worksheet-variable-trace.md
- Read each event carefully
- Fill in the trace table after EVERY event
- Even if a variable didn't change — write its value again
- Watch out for Events 5 and 6 — tricky!
Discussion: The Tricky Events
Event 5: Buying a shield costs 15 gold. What if GOLD goes negative?
→ What should a real program do to prevent this?
Event 6: Removing an item from ITEMS.
→ What if you try to remove something that isn't there?
Real-World Variables
- Game saves — health, score, level, inventory
- Shopping cart — items, total price, quantity
- User accounts — username, email, login_count
- Bank account — balance, last_transaction
Every app you use is managing thousands of variables behind the scenes.
Key Takeaway
A variable is a named storage box.
The name is fixed.
The value can change at any time.
Variables are how programs remember things.
1 / 9
← → or click to advance