Comparison operators
Every decision starts with a boolean question. These operators all evaluate to true or false:
| Operator | Means | Example |
|---|---|---|
=== | exactly equal | score === 100 |
!== | not equal | lives !== 0 |
< / > | less / greater than | speed > 700 |
<= / >= | with equality | score >= highScore |
Use === (triple) to compare. = (single) assigns. Confusing them is one of the most common beginner bugs, if (score = 100) doesn't check anything, it just writes 100.
and / or / not combine questions and **short-circuit*: evaluation stops as soon as the result is known.
Why the game asks questions every frame
A reactive game is a loop of questions. Every single frame the code asks:
- "Am I on the ground?" → if yes, I can jump again.
- "Did I touch a spike?" → if yes, I took damage.
- "Did I pass a coin?" → if yes, score +1.
The grade example in this lesson is structurally identical to that. The only difference is that in a real game those if statements live inside the game loop (we meet the loop in the Advanced tier), so the questions are re-asked ~60 times a second.
The key idea: a program does the same thing every time unless code chooses. Conditionals are the choosing.