JS Sketchbooksee JavaScript think ✏️
← back to the map
2

Making Decisions & Repeating

The big question: “How does a program choose and loop?”

but why do we need this?

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.

in plain words

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.

words you’ll own after this
condition

A yes/no question the program asks, like age >= 18. The answer is always true or false.

branch

One of the paths the program can take after checking a condition (the if part or the else part).

loop

A block of code the machine repeats again and again while a condition stays true.

iteration

One single lap around a loop.

infinite loop

A loop whose stop-condition never becomes false — the machine obediently repeats forever and the page freezes.

truthy / falsy

JavaScript can treat ANY value as a yes or no. Six special values count as “no” (falsy); everything else counts as “yes”.

after this phase, you can…
  • 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 lab — see it move

✏️ This phase’s interactive lab is still being drawn — it arrives together with the phase’s lessons.

the lessons
  1. 2.1
    if / else

    A fork in the road: one condition, one path taken.

  2. 2.2
    Truthy & falsy

    Six values mean “no” — everything else means “yes.”

  3. 2.3
    else-if chains & switch

    Corridors of gates, ladders of cases, and the famous fall-through.

  4. 2.4
    Ternary & short-circuit

    Decisions that produce a value, and logic that skips work.

  5. 2.5
    while loops

    Repeat while a condition holds — and why the tab freezes if it never stops.

  6. 2.6
    for loops

    init / condition / update — the three moments of every lap.

  7. 2.7
    break, continue & nested loops

    Escape hatches, skipped laps, and loops inside loops.

  8. 2.8
    Checkpoint: FizzBuzz, visualized

    The classic interview question — with every decision animated.