Lead the caravan across the dunes โ code that DECIDES: if there's enough water, cross; else, rest in the shade! ๐ด
๐งญ
Today's concept: if / else โ code that chooses!
A condition is a yes/no question. If the answer is true, the if block runs; if false, the else block runs instead. Edit the gold number and watch the caravan's decision flip live!
๐ฏ MissionsDay โฆ
โฆ
โฆ
โฆ
โ โ โ caravan.jsJavaScript
dunesLIVE
๐๏ธ Caravan Mission Step 1 of 5
โฆ
๐ก Hint:โฆ
๐๏ธ Desert Decisions
In Lesson 4 (Variable Vault) you stored values in variables โ tickets, flips, names. A program that only remembers things can't choose. Today you give your code a brain: the if / else statement. It asks a yes/no question, then picks a path. You're the Caravan Master crossing the ๐๏ธ Desert Oasis โ every decision (cross or rest, day or night, open or locked) is an if statement your code decides!
๐งญ if / else Toolkit
if (water >3) {"cross the dune!"}
else {"rest in the shade."}
โ edit the gold number โ the decision flips live!
๐A condition is a yes/no check: water > 3 is true when water is more than 3.
โ If true, the if block runs. If false, the else block runs instead.
โ๏ธEdit the gold box in the code โ the caravan's decision updates live!
๐ฏHit โ Check when the dunes show the right outcome to complete each mission.
๐ Caravan Master!
You just taught your code to think! With if / else, your programs can now make decisions โ check the water, feel the heat, count the camels, and pick the right path. Every game-over screen, every password check, every "is it raining?" app โ they all run on the if statement you mastered today.
๐ What you learned
if (condition) { ... } runs a block only when the condition is true
else { ... } runs when the condition is false โ the backup path
Comparisons: > greater, < less, === exactly equal
&& (AND) needs both sides true; || (OR) needs either
Change a number and the whole decision flips โ that's the power of conditions
๐ Tomorrow: Loop Lab โ teach your code to repeat! "Cross 5 dunes in a row" without writing it five times. ๐๐๏ธ