Simple Math Operators

Lesson

Simple Math Operators

Math is a very powerful resource when it comes to coding as it is often used to control a lot of the logic happening within the code.

We can combine variables with these math operators to check for certain conditions such as if the sprite has no lives left we can tell the game to stop or if the player reaches a certain score to finish the game telling them they won.

There are three main blocks we will use for this shown below used to see if the data within a variable is a certain number, less than or greater than a number.

This image has an empty alt attribute; its file name is image.png

Greater than checks if the number in the left box is greater than the right

This image has an empty alt attribute; its file name is image-1.png

Equal to checks if both numbers are the same

This image has an empty alt attribute; its file name is image-2.png

Less than checks if the number in the left box is smaller than the right

The following link and project demonstrates how to use math operators

https://scratch.mit.edu/projects/351786785

Try playing around the code so that it does different things when the score is different numbers and have a go using the greater than and less than blocks

@

Not recently active