×

typescript · level 1 · unit 7 · lesson 4

  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

Big programs are small pieces working as a team.

Real programs are built from small parts. An array holds the data. A loop walks through it. A function answers one small question, and an if decides what to do with each answer.

Here, isTasty hands back true or false, so its return type is boolean. The loop asks it about every rating in the array, and each tiny piece does one job.

When something goes wrong, you : find the bug, fix it, run again. The checker finds many bugs for you. The rest you hunt down by reading the output.

function isTasty(rating: number): boolean {
  return rating >= 7;
}
for (const rating of [9, 3, 8, 5]) {
  console.log(rating, isTasty(rating));
}

Test each function on its own first, then put the pieces together.