Here's a function that draws a square with
50 pixel sides. That's great but what if I
wanted to draw a square with sides 50 pixels
and another square with sides of 100 pixels?
We shouldn't have to make two separate functions
that do almost the same thing. Instead, we
can use one function with a parameter. Parameters
allow us to pass values into a function that
get used as variables inside the function.
Let's try adding a parameter called like to
this function so we can use it to create squares
of different sizes. In the function editor,
you can edit the name and description like
before but now you can also add a parameter.
Write the name of your parameter in the space
and click Add Parameter. This will create
a red block with the name of the parameter
you just created. Now we can replace the move
forward by 100 block with the parameter Length
so it will move forward by Length. Click save
and close and drag out your new create a square
block from the functions category in the toolbox.
You'll notice there's an empty space next
to length because the function wants to know
what value the parameter Length should have.
Drag a number block from the Math category
and place it in this space. See how you can
use the function again and again with different
lengths to make squares of different sizes?
Try it for yourself!