JAVASCRIPT · ОСНОВЫ · LESSON 08

Three options

else if · about 12 minutes

Learning with progressRead the summary for free. To save the work, log in to the account.
STEP 1

Add the middle way

else if checks for another condition when the first one fails.

const stars = 3;
if (stars >= 5) {
  console.log("Отлично");
} else if (stars >= 3) {
  console.log("Хорошо");
} else {
  console.log("Ещё раз");
}

✦ It'll be good for three stars.

STEP 2

Order matters.

Check from a larger threshold to a smaller one. The program selects the first suitable branch.

const stars = 5;
if (stars >= 5) {
  console.log("Отлично");
} else if (stars >= 3) {
  console.log("Хорошо");
} else {
  console.log("Ещё раз");
}

✦ It'll be great for five stars.

IN-CLASS PRACTICE

Type the code yourself

Type an example manually. Check the names, brackets and signs.

const stars = 4;
if (stars >= 5) {
  console.log("Отлично");
} else if (stars >= 3) {
  console.log("Хорошо");
} else {
  console.log("Ещё раз");
}
Open the editor for class work
HOMEWORK

Solve it yourself

Create const stars = 2. At 5 or more, output «Супер», at 3 or more - «Хорошо», otherwise - «Попробуй ещё». Use if, else if and else.

The answer is hidden. Use similar examples from the lesson notes.

Opening up your homework