Langkau ke kandungan

    Variable Valley

    Variables Umur 6–8

    Store a score in a variable, change it step by step, and work out its value at the end.

    • Umur 6–8
    • 3 misi
    • Permulaan → Semakin mahir → Cabaran

    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. 1. What is lives at the end?

      • 5
      • 9
      • 10
      • 11
      Tunjuk jawapan

      Jawapan: 10. lives starts at 5. 5 + 5 = 10. So lives ends at 10.

    2. 2. What is coins at the end?

      • 2
      • 1
      • 4
      • 3
      Tunjuk jawapan

      Jawapan: 2. coins starts at 4. 4 − 2 = 2. So coins ends at 2.

    3. 3. What is apples at the end?

      • 1
      • 0
      • 2
      • 3
      Tunjuk jawapan

      Jawapan: 0. apples starts at 3. 3 − 3 = 0. So apples ends at 0.

    4. 4. Put the coin program in order.

      • change coins by 1
      • collect a coin
      • set coins to 0
      • say coins
      Tunjuk jawapan

      Jawapan: set coins to 0 → collect a coin → change coins by 1 → say coins. Set the variable first, then change it, then show it.

    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.