Functions: name a group of blocks

Knowledge Videos

Short animated explainers, organised by subject.

Functions: name a group of blocks

A function is a named group of blocks you define once and call many times. Define, call and parameter, with a draw-a-square function.

Transcript

Sometimes you need the same group of blocks again and again. A function gives that group a name. In Scratch it is called a My Block.

You define the function once. Here, the function draw square contains the blocks that draw a square.

Then you call it by name. Call draw square, and the whole group runs. Call it three times, and you get three squares, without copying any blocks.

A function can also take an input, called a parameter. Draw square with size one hundred, or size fifty. The same recipe, with different amounts.

Remember: a function is a named group of blocks. Define it once, then call it whenever you need it.

More in this series