if
JavaScript · Unit 2: Conditionals
- Full plan
- JavaScript
- 10 exercises
if asks a question. If the answer is true, it runs what sits between the braces; if it is false, it skips it.
The condition goes inside parentheses and the block between { and }.
let temp = 90;
if (temp > 80) {
console.log("It is hot");
}Prints
It is hot
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
Fill in the blank so only people who can already vote get the message.
3. Predict the output
What does this code print?
4. Predict the output
What does this code print?
5. Predict the output
What does this code print?
6. Complete the code
Fill in the blank so it warns you when the number is odd.
7. Find the bug
It should warn you only if it is cold, and it is 68 degrees. Which line has the error?
8. Put the lines in order
The person types 20. Put the lines in order to decide whether they can get into an R-rated movie.
9. Multiple choice
What does this code do?
10. Predict the output
What does this code print?
It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.