Grade 8 · Media & Informatics
Use variables to store and change values in a simple program.
A variable is a named box in a program's memory that holds a value. You give it a name, like score or playerName, and the program can read what is inside or put something new in. Clear names make a program much easier to understand.
The power of a variable is that its value can change while the program runs. You might start with score = 0, then later write score = score + 10 each time the player wins points. The name stays the same; the value inside is updated.
Variables hold different kinds of value: numbers (score = 10), text or 'strings' (name = 'Mara'), and true/false. Choosing a clear name and the right kind of value is the start of writing a program that does what you mean.
Have a go right here. Nothing is saved and you can retry as much as you like. Create a free account when you want to save your progress and get Archie, your tutor.
Create a free account to save your progress, track mastery and ask Archie, your tutor, for a hand.
Already with us? Open this lesson in learncoach.ch for mastery tracking and Archie, your tutor.