Starlit Daily

📚 › JavaScript: make pages do things

5. Decisions with if and else

ستتم ترجمة هذا المقال تلقائيًا. يُعرض بالإنجليزية حاليًا.

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.

عرض المثال

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

✍️ دورك الآن

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

← العودة إلى الدورة