A function is basically a series of steps that you teach the computer – it then learns the steps and can use them when you ‘call it’. The idea is you don’t need to continually tell the computer how to do something as it already knows.

In this case, we are going to teach the computer how to work out the percentage of a number. The steps are:

Take the number and divide it by 100

Multiply that answer by the percentage you want

Print out that answer

In Scratch, you can do this using the MAKE BLOCK function. You define the block and put in how many numbers you need. In the function, you define the steps and return the answer.

You then ‘call the function’ by adding the block to the code.

REPETITION is a very useful function on coding and saves time rather than doing a long list of code. The basic idea is that you can have a variable and then write code so the variable increases by 1 (or another number) until a certain number is reached.

Example: To get Scratch to work out the 5x table

Using pseudocode:

Declare a variable called MULTIPLIER

Make MULTIPLIER = 0

Work out 5 x MULTIPLIER

PRINT the answer

Add 1 to MULTIPLIER

Repeat steps 3 – 5

STOP the code when MULTIPLIER = 12

This is how the code looks like in Scratch.

Delivering the computing curriculum to primary schools