Memory Box

Variables: Named boxes that hold values


Year 7 Computer Science

Live Demo Setup

Three volunteers each hold a variable card:

HEALTH
10
GOLD
0
ITEMS
[ ]

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:

Your Turn — Trace the Adventure

Take the worksheet-variable-trace.md

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


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