Starlit Daily

📚 › JavaScript: make pages do things

5. Decisions with if and else

Este artículo se traducirá automáticamente. Por ahora se muestra en inglés.

An if statement runs code only when its condition is true. else runs when it is false, and else if checks another condition.

if (score >= 50) checks whether the score is 50 or more.

Ver ejemplo

let age = 20;
if (age >= 18) {
  console.log("adult");
} else {
  console.log("minor");
}

✍️ Ahora te toca

Let score = 72. Print pass if the score is 50 or more, otherwise fail.

← Volver al curso