Lesson 4 of 20
Conditions
Run different code based on a decision.
Introduction
An if statement runs code when a condition is true. else if and else provide alternative paths.
Keep conditions readable and prefer strict comparisons so values do not change type unexpectedly.
Key insight
Run different code based on a decision.
Example
const age = 20;
if (age >= 18) {
console.log("Adult");
} else {
console.log("Minor");
}This example shows the core conditions idea in a small, runnable program.
Real-world example
Login screens use conditions to show success, validation and permission states.
Test yourself
2-question check
1
What is the main idea in Conditions?
2
Where can conditions be useful?
Ready to check your understanding?
Answer every question, then submit your quiz.
Try it yourself
JavaScript compiler
Runs in your browser. Nothing is sent to a server.
Output appears here
Practice challenge
Show a different message when a score is below 50.