If / Else
(Con-di-tion-als)
What is it? 🤔
This is how computers make a Choice.
It's like a fork in the road. The computer asks a question (like "Is it raining?"). If the answer is YES, it goes one way. If NO, it goes the other way!
Example: What to Wear? 🌦️
Raining?
Take Umbrella
Wear Shades
💡 Fun Fact
You can chain these together! "If it's raining, take umbrella. Else If it's snowing, take a coat. Else, wear a t-shirt!"
🎮 Try It Yourself!
Switch the weather to see what the character wears.
if (weather == "sunny") {
wear("sunglasses");
} else {
wear("raincoat");
}
🕵️ Secret Mission 🕵️