Beginner Coding with Blocks
Chapter
>
Level

Functions and Procedures
Passing functions as arguments

Objective

Count the mandrakes and mushrooms in the swamp using functions.

Count the various strange objects located in the swamp, using custom functions to make it easier to format your code. Walk to the X marks and count, how many "Red Mandrake", "Blue Mandrake", "Poison Mushroom" and then count all of them together at the light X mark.

Custom functions are capable of returning values, these values can also be used as arguments in other functions.

Use the define function to return block to create a function named name_and_number with two parameters: name and number. In the return value, use a text join block to combine "There are ", the number parameter, " ", and the name parameter.

By using the define function to return block, the function itself will return a value, in this case a string made with the arguments you entered. Use the value from this function by calling it with the call function block and connecting it to the speak block. For example: use call function for name_and_number with "Red Mandrake" and 4 as arguments, then connect it to the speak block.

For the final light X mark create another custom function using define function to return named add_numbers with three parameters: num1, num2, and num3. In the return value, use add blocks to add all three numbers together and return the total of items you counted.

Code book