- script.js
JavaScript
var score = 0;
var total = 0;
var victoryPoints = 100;
var misses = 0;
while (total < victoryPoints) {
score = muffin.getScore();
if (score < 0) {
console.log('You missed!');
misses++;
} else {
total += score;
console.log('Result of the shot: ' + score);
}
}
console.log(total);
Result
Goalscompleted
Let’s make it so that the loop stops if the number of misses goes up to three.
- Add condition
if (misses >= 3) { }
to the beginning of the loop body. - Inside this condition, add the
break
operator.
Comments