Making Decisions & Repeating
The big question: “How does a program choose and loop?”
A program that can’t choose does exactly the same thing every single run — it could never check a password, apply a discount, or decide whether a test passed. And without loops, checking 500 items would mean writing the same line 500 times. Choosing and repeating are what turn a list of instructions into actual behavior.
So far, programs run straight down like a shopping list. Real programs feel smart because they can do two more things: choose between paths, and repeat work without getting tired.
Choosing works like a fork in a road: the program checks a condition (a question whose answer is true or false) and takes one branch or the other. Repeating is a loop: “keep doing this until I say stop.” A loop that checks 10,000 items takes the machine a blink.
Almost every bug you’ll ever hunt as a tester lives in a choice or a loop that went the wrong way — so we’ll watch them run step by step until the path is always visible in your head.
A yes/no question the program asks, like age >= 18. The answer is always true or false.
One of the paths the program can take after checking a condition (the if part or the else part).
A block of code the machine repeats again and again while a condition stays true.
One single lap around a loop.
A loop whose stop-condition never becomes false — the machine obediently repeats forever and the page freezes.
JavaScript can treat ANY value as a yes or no. Six special values count as “no” (falsy); everything else counts as “yes”.
- ✓Trace which branch an if/else will take, before running it
- ✓Write a loop and say exactly how many times it runs
- ✓Spot why a loop never stops — or never starts
- ✓List the falsy values from memory
✏️ This phase’s interactive lab is still being drawn — it arrives together with the phase’s lessons.
- 2.1if / else
A fork in the road: one condition, one path taken.
- 2.2Truthy & falsy
Six values mean “no” — everything else means “yes.”
- 2.3else-if chains & switch
Corridors of gates, ladders of cases, and the famous fall-through.
- 2.4Ternary & short-circuit
Decisions that produce a value, and logic that skips work.
- 2.5while loops
Repeat while a condition holds — and why the tab freezes if it never stops.
- 2.6for loops
init / condition / update — the three moments of every lap.
- 2.7break, continue & nested loops
Escape hatches, skipped laps, and loops inside loops.
- 2.8Checkpoint: FizzBuzz, visualized
The classic interview question — with every decision animated.