Arithmetic Operators in Scratch

Updated: February 17, 2022
No Credit Card Required
ClaimYour
FreeTrialClass

Transcript

Welcome back. How are you?

Today we're going to introduce how to use ARITHMETIC OPERATORS in Scratch. The four ARITHMETIC OPERATORS we're going to cover today are addition, subtraction, multiplication, and division.

You're probably already all familiar with these from your math class. But if not, you can experiment with them and scratch or work on the exercises with one of your parents or maybe an older brother or sister, you're ready. Let's code.

Each of the ARITHMETIC OPERATORS has its own Scratch block, into which you can enter the numbers to be used for the math operation. Here's an example. MOVE 30 PLUS 70 STEPS is the same as MOVE 100 STEPS.

Using the ARITHMETIC OPERATORS with two numbers, though, isn't really useful, because well, you could just solve it and then put the answer into your code instead. However, ARITHMETIC OPERATORS are much more useful with VARIABLES.

In this example, we set the Variable Distance to any number we want, and then have the sprite move to the right that many steps, wait a second, and then move back. As you can see, we added the multiplication operator to MOVE TO THE LEFT 100 STEPS, which makes our code more DRY. Remember, DRY stands for DON'T REPEAT YOURSELF, and this is a great thing.

Now, do you remember the functions we created to move our sprite on a diagonal? We created two functions and used the CHANGE X BY block to have them move to the right. A different approach here would be to create a FUNCTION with an operator in the function like this. Now with this new way, we can change the distance or step size by changing one number so it's a lot quicker when we want to edit it.

Alright, this was a quick lesson to illustrate how to use these additional features in Scratch. Now, please move on to the exercises and I'll see you soon

Loading...