{ }codelper

Learn with tiles › 33

Calling a function

Give a group of tiles a name, and use it by calling the name.

1

A function is a group of tiles with a name. The block of tiles at the bottom with the label greet is a function. Inside it is a tile that writes "Hello!".

A function does nothing if you only make it. You have to call its name to run the tiles inside. The greet() tile under "when started" is the tile that calls the function.

Put calling tiles under "when started". If you put "greet()" inside the function greet, it calls itself without end and stops.

The "make a new function" tile that you also see in the drawer is for making your own function later. You do not use it now.

To do Call the function greet three times so that Hello! appears on three lines.

Loading tiles…

2

This time the function is empty. Fill it in so that calling the function drawLine makes ----- appear.

You fill it in only once, and both places that call it change. This is why we use functions.

To do Make -----, Menu, ----- appear in order on three lines.

Loading tiles…

3

A function is good when you need to do the same thing in several places. It is like the chorus of a song.

The chorus La la la must come after Verse 1 and also after Verse 2.

To do Make Verse 1, La la la, Verse 2, La la la appear in order.

Loading tiles…

Next: Passing values →