Langkau ke kandungan

    Function Factory

    Functions Umur 7–9

    Bundle steps into named functions, call them again and again, and give them inputs to change what they do.

    • Umur 7–9
    • 3 misi
    • Permulaan → Semakin mahir → Cabaran

    A function is a named set of instructions you can use again and again. Instead of writing the steps for “draw a square” four times, you write them once, name them, and call the name whenever you need them.

    Apa yang akan dipelajari anak anda

    • Know what a function is and why it is useful
    • Predict what happens when a function is called several times
    • Use functions with inputs (parameters), like size or name
    • Work out what a simple function gives back

    Write once, use many times

    In Scratch, “Make a Block” creates a function. Fix a bug inside it and it’s fixed everywhere the block is used. Functions can take inputs: drawSquare(5) and drawSquare(10) use the same steps to draw different sizes.

    Contoh soalan

    Berikut ialah beberapa soalan seperti dalam misi pertama. Bolehkah anda menjawabnya?

    1. 1. Why do programmers use functions?

      • To make programs longer
      • To add bugs
      • To slow the computer down
      • So they don’t have to write the same code again and again
      Tunjuk jawapan

      Jawapan: So they don’t have to write the same code again and again. Write it once, use it many times.

    2. 2. What is a function in coding?

      • A type of keyboard
      • A kind of bug
      • A named set of instructions you can use again
      • A picture
      Tunjuk jawapan

      Jawapan: A named set of instructions you can use again. Functions bundle steps under one name.

    3. 3. You make a block called “jump”. What happens when the program uses it?

      • All the steps inside “jump” run
      • Nothing
      • The sprite is deleted
      • The block changes its name
      Tunjuk jawapan

      Jawapan: All the steps inside “jump” run. Calling a function runs its steps.

    4. 4. Match each word to its meaning.

      • call
      • function
      • input
      • a named set of steps
      • information given to a function
      • use the function
      Tunjuk jawapan

      Jawapan: call → use the function · function → a named set of steps · input → information given to a function. Functions let us reuse code.

    Tip untuk orang dewasa

    • Invent a family “function”, like “bedtime routine”, and list its steps.
    • Play a function machine game: “double” — you say 4, they say 8.