Class 5 (Grade 5) ยท Computer Science
Block Coding with Variables: Class 5 Computer Science
A variable is a named box that stores a value a program can change, like a score or a timer.
- Lesson
- 3 quizzes
- Worksheet PDF
A step-by-step lesson, 3 self-marking quizzes and a printable worksheet, all on Block Coding with Variables for Class 5.
Block Coding with Variables: the short answer
If you use set score to 1 every time a coin is collected, the score will never go above 1.
Learn it: the lesson
Block Coding with Variables8 steps ยท one idea at a time ยท quick check at the endStart the lesson โWhat the lesson covers8 steps ยท tap to see
1A box with a name
A variable stores a value that can change while a program runs.
Learn this in the lesson โ2Set and change
Two blocks do most of the work: set score to 0 puts a value in the box, replacing what was there.
Learn this in the lesson โ3Using a variable in a condition
Variables are often checked with if: If lives = 0, then say "Game over" and stop.
Learn this in the lesson โ4A countdown timer
Set time to 10. Repeat until time = 0: wait 1 second, change time by โ1.
Learn this in the lesson โ5Naming variables well
Give variables clear names that say what they store: score, coinsCollected, speed.
Learn this in the lesson โ6Watch out: set and change are different
Set replaces the value. Change adds to it.
Learn this in the lesson โ7Track two variables
Follow the program line by line.
Learn this in the lesson โ8Set or change?
Setting a variable replaces its value.
Learn this in the lesson โ- Quick check: see what you remember
Block Coding with Variables: Class 5 Computer Science notes
A box with a name
A variable stores a value that can change while a program runs. Think of it as a labelled box.
A game might have variables called score, lives and time.
Set and change
Two blocks do most of the work:
- set score to 0 puts a value in the box, replacing what was there.
- change score by 1 adds to the value already there. change lives by โ1 takes one away.
Set a variable at the start of the program, so every game begins fairly.
Using a variable in a condition
Variables are often checked with if:
If lives = 0, then say "Game over" and stop. If score > 20, then go to level 2.
The program can make choices based on what has happened so far.
A countdown timer
Set time to 10. Repeat until time = 0: wait 1 second, change time by โ1. Say "Time's up!"
The variable goes 10, 9, 8 โฆ 0. Then the loop stops and the message appears.
Naming variables well
Give variables clear names that say what they store: score, coinsCollected, speed.
A name like x or thing makes a program hard to read and fix later.
Watch out: set and change are different
Set replaces the value. Change adds to it. Mixing them up is a very common bug.
If you use set score to 1 every time a coin is collected, the score will never go above 1.
Key facts
- A variable is a named store for a value that can change.
- Set replaces the value; change adds to it.
- Use variables in conditions, give them a start value and a clear name.
Block Coding with Variables MCQs with answers
Tap an answer to check it.
A variable stores a value thatโฆ
Answer: A. can change while the program runs
Set time to 10. Repeat until time = 0: wait 1 second, change time by โ1. How many times does the loop run?
Answer: B. 10
score = 0. Each coin runs change score by 2 and three coins are collected. Then the player is hit and change score by โ1 runs. What is the score?
Answer: B. 5
Which is the best variable name?
Answer: A. score
More questions in the 3 quizzes below โ ยท All Class 5 Computer Science MCQs with answers โ
Practise real quizzes on this topic: 3 quizzes
Each quiz marks itself the moment it is finished and explains every answer. Start easy and work up.
Print it: the worksheet Save to Pinterest
๐จ๏ธBlock Coding with VariablesA variable stores a value that can change; set replaces it and change adds to it. Children trace set and change blocks, follow a countdown timer, and reason about conditions and good variable names.See the worksheet โโฌ Download free PDFFree sample copy with a light QuizByt mark. A free account gives you more.