Comparisons
JavaScript · Unit 2: Conditionals
- Full plan
- JavaScript
- 10 exercises
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. Predict the output
What does this code print?
2. Complete the code
The kids ticket is for ages 12 and under. Fill in the blank so it prints
true.3. Multiple choice
What does
price === 50do?4. Complete the code
Fill in the blank so it prints
truewhen the answer is 42.5. Predict the output
What does this code print?
6. Find the bug
It should print
truefor anyone 18 or older. Ava is 18. Which line has the error?7. Predict the output
What does this code print?
8. Predict the output
The person types 5. What does it print?
9. Put the lines in order
The person types 18. Put the lines in order to say whether they are an adult.
10. Multiple choice
What does this code do?
It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.