Operators: Math Superpowers! โโโ๏ธโ
Operators are special symbols that do things like math and comparisons. They're like tools in a toolbox!
๐งฎ Math Operators
You already know these from math class! Computers use the same symbols (mostly).
Addition
Add things together
Subtraction
Take things away
Multiplication
We use * instead of ร
Division
We use / instead of รท
๐ฎ Math in Video Games!
Games use math operators ALL the time. Here's what happens behind the scenes:
You collect 10 coins!
coins = coins + 10 You get hit! Lose 25 health!
health = health - 25 Double damage power-up!
damage = damage * 2 Split loot between 4 players!
share = treasure / 4 โ๏ธ Comparison Operators
These help the computer compare things and answer questions! The answer is always true or false.
=== Equals (Is the same as?)
5 === 5 is true โ
5 === 3 is false โ
!== Not Equals (Is different?)
5 !== 3 is true โ
5 !== 5 is false โ
> Greater Than
10 > 5 is true โ
< Less Than
3 < 7 is true โ
>= Greater or Equal
5 >= 5 is true โ
<= Less or Equal
4 <= 6 is true โ
๐น๏ธ Games Ask Questions Too!
Games use comparisons to make decisions. Here are some examples:
Game Over Check
health <= 0 If true, game over!
Level Up Check
points >= 1000 If true, level up!
Door Check
keys > 0 If true, can open door!
Shop Check
coins >= price If true, can buy item!
๐ง Quiz Time!
What do these equal? True or False?
10 > 5 Answer: true โ
3 === 3 Answer: true โ
7 < 2 Answer: false โ
100 !== 50 Answer: true โ
โญ Remember This!
- 1
Math operators do calculations: + - * /
- 2
We use * for multiply and / for divide
- 3
Comparison operators ask questions: === !== > < >= <=
- 4
Comparisons always answer true or false