basiccodingconcept.online

Operators: Math Superpowers!

How Operators Work in Code

How Do Video Games Use Math Operators Behind the Scenes?

Games run on Math Operators constantly — every time you collect, take damage, or share loot, one of four symbols runs a calculation.

Addition

performs Addition — coins increase by 15 every time you pick them up

coins = coins + 15

Subtraction

performs Subtraction — health drops by 30 each time an enemy hits you

health = health - 30

Multiplication

performs Multiplication — a power-up doubles damage by multiplying it by 4

damage = damage * 4

Division

performs Division — loot splits between four players when treasure is divided by 6

share = treasure / 6

What Symbols Do Computers Use for Math Instead of × and ÷?

Computers use symbols to do calculations — most match what you already know from math class, with two differences.

  • performs Addition and adds things together
  • performs Subtraction and takes things away
  • performs Multiplication and is used instead of × to multiply
  • performs Division and is used instead of ÷ to divide

What Do Comparison Operators Return When They Ask Questions?

Comparison Operators help the computer ask questions and produce either true or false as the answer.

Equals

means Equals — returns true when two values are the same

4 === 4

Not Equals

means Not Equals — returns true when two values are different

3 !== 2

Greater Than

means Greater Than — checks if the left number is larger

6 > 2 is true

Less Than

means Less Than — checks if the left number is smaller

2 < 9 is true

Greater or Equal

means Greater or Equal — returns true when the left value matches or exceeds the right

7 >= 7

Less or Equal

means Less or Equal — returns true when the left value matches or falls below the right

2 <= 8

How Do Comparisons Make Decisions That Change the Game?

Comparisons let the computer make decisions by checking if a condition answers true or false.

health triggers game over when health <= 10 returns true

points trigger level up when points >= 100 returns true

keys enable opening a door when keys > 0 returns true

coins are compared with price — coins >= price must return true before the player can buy an item