Back to Real If / Then
Code Studio · Level 3

If / Then Builder

Students change a boolean variable from true to false and test the result.

20-25 min Ages 9-12 Builder JavaScript

Conditions can ask about numbers

So far the guard only checked a yes/no box. Now the guard can do math! A comparison like playerScore >= 10 asks a question about a number — "is the score at least 10?" — and JavaScript answers true or false all by itself.

  1. 1

    A comparison makes a boolean

    let hasEnoughPoints = playerScore >= 10; opens the playerScore box, finds 12, checks "is 12 at least 10?" and puts the answer — true — into the new box. You never typed true; the program figured it out.

  2. 2

    The comparison symbols

    > means greater than, < means less than, >= means at least (greater or equal), and <= means at most. The alligator trick still works: the open mouth always chomps the bigger number.

  3. 3

    Change the number, change the choice

    Run the example: with a score of 12, the rainbow shield unlocks. Now change 12 to 7 and run again — the score still prints, but the shield stays locked because 7 isn't at least 10. This is exactly how real games decide when you've earned the next level.

Code Editor

Change the choice.

Example code
let playerScore = 12;
let hasEnoughPoints = playerScore >= 10;

say("Score: " + playerScore);

if (hasEnoughPoints) {
  say("Unlock the rainbow shield.");
}
Output

Program result

Robot ready to speak your strings

Type real JavaScript, then run it.