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 score at the end?
- 0
- 3
- 1
- 5
Tunjuk jawapan
Jawapan: 0. score starts at 3. 3 − 1 = 2, 2 − 2 = 0. So score ends at 0.
2. What is coins at the end?
- 4
- 1
- 3
- 5
Tunjuk jawapan
Jawapan: 4. coins starts at 1. 1 − 1 = 0, 0 + 4 = 4. So coins ends at 4.
3. What is score at the end?
Tunjuk jawapan
Jawapan: 5. score starts at 5. 5 − 5 = 0, 0 + 5 = 5. So score ends at 5.
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.