Parameters in Scratch

Updated: February 17, 2022
No Credit Card Required


Hi, how you doing? Today, we're going to introduce PARAMETERS and learn how to create FUNCTIONS with PARAMETERS. So, let's code.

Last lesson, we learned that a FUNCTION is a block of code that can be written once and be used in multiple places in your program.

Before that, we learned that a Variable is used to store information for use in the computer program. So what if we combine a FUNCTION with a variable and combine a variable with a FUNCTION?

I mean, why would we want to combine a FUNCTION and a variable? Any ideas? Go ahead, raise your hand. Exactly. This allows us to slightly change the FUNCTION.

In our last lesson, we created a FUNCTION we called Move And Turn to create a square 100 steps on each side. Say we wanted a square with 70 Steps on a side or 25 Steps on a side or 40 Steps on a side, we'd have to edit our code to change the number of steps in the Move And Turn FUNCTION. So let's add a variable which we call a PARAMETER to our FUNCTION.

After clicking MAKE A BLOCK, click the left most option to add an input number or text. Now you should have a screen that looks like this. Name, our PARAMETER as “Number Of Steps”. Each time the FUNCTION is called, we move forward a certain number of steps and turn 90 degrees, then wait half a second.

How many steps do we move forward? Well, that's defined in the PARAMETER. To change the width of the square. All we have to do is change the PARAMETER value from 100 to literally any other number. It's so much easier.

Alright, nice job today guys. You are doing really well and I'll see you in the next lesson.