A variable is a labelled box that stores a value, like a score or a number of lives. Programs can set a variable and change it as the program runs. Year 2 coders trace short programs to find a variable’s final value.
Apa yang akan dipelajari anak anda
- Know that a variable stores a value with a name
- Follow “set” and “change” blocks step by step
- Work out the final value of a variable
Keeping score
Every game with a score uses a variable. “Set score to 0” starts it; “change score by 1” adds one each time you collect a star. Working through a program one line at a time — tracing it — is how programmers check what a variable will be.
Contoh soalan
Berikut ialah beberapa soalan seperti dalam misi pertama. Bolehkah anda menjawabnya?
1. What is coins at the end?
Tunjuk jawapan
Jawapan: 1. coins starts at 4. 4 − 3 = 1. So coins ends at 1.
2. What is coins at the end?
- 1
- 2
- 3
- 0
Tunjuk jawapan
Jawapan: 0. coins starts at 3. 3 − 3 = 0. So coins ends at 0.
3. What is coins at the end?
Tunjuk jawapan
Jawapan: 5. coins starts at 0. 0 + 5 = 5. So coins ends at 5.
Tip untuk orang dewasa
- Keep score in a board game on paper and talk about “changing score by 2”.
- Use a box labelled “sweets” and add or take away while counting.