A variable is a named box that stores a value — like a score in a game. Programs set variables and then change them as things happen.
Apa yang akan dipelajari anak anda
- Understand that a variable stores a value
- Work out a variable’s value after it is changed
- Follow changes made inside a loop
Keeping score
Every game children play has variables: score, lives, coins. Variable Valley uses Scratch-style blocks such as “set score to 3” and “change score by 2”, so children can trace the value step by step, just as they will in real coding apps.
Contoh soalan
Berikut ialah beberapa soalan seperti dalam misi pertama. Bolehkah anda menjawabnya?
1. What is lives at the end?
- 6
- 5
- 7
- 1
Tunjuk jawapan
Jawapan: 6. lives starts at 1. 1 + 2 = 3, 3 + 3 = 6. So lives ends at 6.
2. What is gems at the end?
Tunjuk jawapan
Jawapan: 6. gems starts at 0. 0 + 4 = 4, 4 + 2 = 6. So gems ends at 6.
3. What is gems at the end?
- 2
- 3
- 0
- 1
Tunjuk jawapan
Jawapan: 1. gems starts at 3. 3 − 2 = 1. So gems ends at 1.
4. Number or text variable?
- name = "Mia"
- age = 9
- score = 120
- colour = "blue"
- lives = 3
Bakul: Number · Text
Tunjuk jawapan
Jawapan: Number: age = 9, lives = 3, score = 120 · Text: colour = "blue", name = "Mia". Text goes in quotation marks.
Tip untuk orang dewasa
- Keep score in a board game and talk about it as a variable that changes.
- Use a jar of counters as a “variable” and follow instructions to change it.