Beginner Coding with Blocks
Chapter
>
Level
Functions and Procedures
Functions with Arguments
Objective
Use a custom function to water all the crops on the field writing no more than thirteen (13) lines of code.
A parameter is a value you pass to a function when calling it. When creating custom functions you are able to add parameters to add some variation to the code the function executes.
There are several crops that need watering in succession, use a custom function to simplify your code and reduce the amount of lines you need to write.
Use the define function block to create a function named water_crops. Add a parameter called count to the function. Inside the function, use a for loop block with variable x from 0 to count - 1. Inside the loop, move forward 2 steps, turn left, water, and turn right.
The parameter count in the above function allows you to control how many times the loop repeats. With this function, not only are you able to run a loop using a single function call, but you are also able to set how many times you would like the loop to repeat. For example: calling water_crops with the argument 4 will run the for loop inside the function four (4) times.
Define and use this function to water the crops writing no more than thirteen (13) lines of code.