×

typescript · level 1 · unit 4 · lesson 1

  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

An if runs code only when its is true.

Picture a fork in the path with a sign: Is it Saturday? An if asks a condition like that, inside round brackets. If the answer is true, the lines inside run. If not, they are skipped.

To ask whether two values match, use three equals signs, . It gives true or false. One = puts a value in a box, so it cannot ask questions.

The lines that belong to the if sit inside curly brackets, { and }. That group is a . Indent the lines inside by two spaces, so people can see where it starts and ends.

let day: string = "Saturday";
console.log(day === "Saturday");
if (day === "Saturday") {
  console.log("Pancakes for breakfast!");
}
console.log("Time to get dressed.");

Lines after the closing curly bracket sit outside the if, so they run every time.