Skip to the content

Comparisons

JavaScript · Unit 2: Conditionals

A comparison asks JavaScript a question, and the answer is always true (yes) or false (no), in lowercase.

< is less than and > is greater than. <= and >= accept equal too.

console.log(5 > 3);
console.log(2 > 8);
console.log(4 <= 4);

Prints

true
false
true

The rest of the explanation is in the lesson, which is part of the full plan.

Exercises in this lesson

You do them in the app, which checks them on the spot and explains why.

  1. 1. Predict the output

    What does this code print?

  2. 2. Complete the code

    The kids ticket is for ages 12 and under. Fill in the blank so it prints true.

  3. 3. Multiple choice

    What does price === 50 do?

  4. 4. Complete the code

    Fill in the blank so it prints true when the answer is 42.

  5. 5. Predict the output

    What does this code print?

  6. 6. Find the bug

    It should print true for anyone 18 or older. Ava is 18. Which line has the error?

  7. 7. Predict the output

    What does this code print?

  8. 8. Predict the output

    The person types 5. What does it print?

  9. 9. Put the lines in order

    The person types 18. Put the lines in order to say whether they are an adult.

  10. 10. Multiple choice

    What does this code do?

Do this lesson

It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.

See all lessons →