×

typescript · level 1 · unit 5 · lesson 3

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

Put an if inside a loop to check every number.

A loop can hold any code, even an if. Each lap, the if asks its question again with the new number, so the loop checks them one by one.

% gives the : what is left over after dividing. 7 % 2 is 1, because two goes into seven three times with one left. Even numbers leave nothing, so for them % 2 gives 0.

The if block sits inside the loop block, so it is indented two more spaces. Each closing curly bracket lines up with the line that opened it.

for (let house = 1; house <= 6; house++) {
  if (house % 2 === 0) {
    console.log("Letter for house", house);
  }
}

Read house % 2 === 0 as “house divides by 2 with nothing left over”.