What are Conditionals?
Conditionals help computers make choices. They ask questions and do different things based on the answers - just like you do every day!
๐ฆ Making Decisions Every Day
You already use conditionals in real life:
๐ค๏ธ Real Life Example: Getting Dressed
IF it's raining, THEN take an umbrella.
IF it's cold, THEN wear a jacket.
ELSE (if it's not cold), wear a t-shirt!
๐ป How Computers Write It
if (weather ===
"rainy") {
bringUmbrella();
} else {
enjoyTheSun();
}
bringUmbrella();
} else {
enjoyTheSun();
}
๐ฎ Try It: Weather Decision Maker
Click on the weather to see what the computer decides:
โ๏ธ
Sunny
๐ง๏ธ
Rainy
โ๏ธ
Snowy
๐จ
Windy
Click a weather option to see the computer's decision!
๐ Key Words to Remember
- IF: Checks if something is true
- THEN: What happens if the condition is true
- ELSE: What happens if the condition is false
- Condition: The question being asked