Computer Science
Grade 3
20 min
Score Keeping
Score Keeping
Tutorial Preview
1
Introduction & Learning Objectives
Learning Objectives
Define the term 'variable' as a container for information that can change.
Explain why a variable is useful for keeping score in a game.
Create a new variable and give it a starting value, like zero.
Use a 'change variable by' command to increase a score.
Use a 'set variable to' command to reset a score.
Identify the name and the value of a variable in a simple program.
By the aend of this lesson, students will be able to connect an event, like clicking a character, to changing a score variable.
Have you ever played a video game and wondered how the computer remembers your score? 🎮 Let's find out how its brain works!
We are going to learn about a special computer memory box called a 'variable'. Variables ar...
2
Key Concepts & Vocabulary
TermDefinitionExample
VariableA special container in the computer's memory that holds one piece of information. Its name stays the same, but the information inside (its value) can change.A variable named `score` could hold the number `10`.
Variable NameThe special name you give to your variable so you can find it later. It should describe what it holds.Good names are `playerScore`, `coins`, or `lives`.
ValueThe information that is stored inside the variable at any moment.If the variable is `score`, its value could be `0`, then `1`, then `2` as you play.
Creating a VariableThe action of making a new, empty variable and giving it a name for the first time.In a coding program, you click 'Make a Variable' and type in the name `score`.
Setting a VariablePutting the first value i...
3
Core Syntax & Patterns
The 'Set' Rule
set [variable_name] to [value]
Use this at the beginning of a game to start the score at a specific number, usually 0. It's like resetting the scoreboard for a new game.
The 'Change' Rule
change [variable_name] by [amount]
Use this whenever you want to add or subtract from the current score. To add a point, you change it by 1. To lose a point, you change it by -1.
The Naming Rule
Give variables names that describe what they hold.
A variable named `score` is much easier to understand than a variable named `x` or `box1`. This helps you and others read your code.
4 more steps in this tutorial
Sign up free to access the complete tutorial with worked examples and practice.
Sign Up Free to ContinueSample Practice Questions
Challenging
A programmer is testing their game. They notice the score correctly goes up when they collect coins, but when they click the green flag to restart, the score doesn't go back to 0. What piece of code is most likely missing?
A.block like `WHEN green flag clicked, SET score TO 0`
B.block like `WHEN coin touched, CHANGE score BY 1`
C.block like `WHEN game over, HIDE score variable`
D.block like `WHEN green flag clicked, SHOW score variable`
Challenging
You want to add a 'Double Points' power-up. When active, every coin is worth 2 points instead of 1. You have a `score` variable. What OTHER variable would be most helpful to make this work?
A.variable like `isDoublePointsActive` that can be true or false
B.second score variable called `double_score`
C.variable to count the number of coins on the screen
D.variable to store the player's name
Challenging
In a two-player game with variables `player1_score` and `player2_score`, which condition should be used inside an IF block to correctly show a 'Player 2 Wins!' message?
A.IF player1_score > player2_score
B.IF player2_score > player1_score
C.IF player1_score = player2_score
D.IF player2_score > 0
Want to practice and check your answers?
Sign up to access all questions with instant feedback, explanations, and progress tracking.
Start Practicing Free