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.
What your child will learn
- 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.
Example questions
Here are a few questions like the ones in the first quest. Can you solve them?
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
Show answer
Answer: So they don’t have to write the same code again and again. Write it once, use it many times.
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
Show answer
Answer: A named set of instructions you can use again. Functions bundle steps under one name.
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
Show answer
Answer: All the steps inside “jump” run. Calling a function runs its steps.
4. Match each word to its meaning.
- call
- function
- input
- a named set of steps
- information given to a function
- use the function
Show answer
Answer: call → use the function · function → a named set of steps · input → information given to a function. Functions let us reuse code.
Tips for grown-ups
- Invent a family “function”, like “bedtime routine”, and list its steps.
- Play a function machine game: “double” — you say 4, they say 8.