Interactive online courses HTML Academy
2026-03-09 14:10 Diff

Hooray! Our program works! But we always win.

Let’s make it a bit more intriguing and interrupt the loop as soon as we missed three times.

To do this, we need a variable that will count misses, let’s call it misses. Every time a player misses, we will increase this variable by one.

The muffin.getScore() command returns -1 if the player missed. Therefore, inside the loop, you need to add a check to make sure that the result of the current shot is less than zero. And if the check is passed, we will then record the miss in the console and increase the miss counter by one.

Actions inside the loop will look like this:

  1. We get the result of the shot.
  2. Check that the shot result is less than zero. If this is the case, then go to step three, otherwise go to step four.
  3. Record the miss in the console and increase the miss counter by one.
  4. Increase total result total and log the shot result in the console.