- script.js
JavaScript
var score = 0;
var total = 0;
var victoryPoints = 100;
var misses = 0;
while (total < victoryPoints) {
if (misses >= 3) {
break;
}
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 log the results in the console. Instead of console.log(total);
, log game results as follows:
- After the loop, add a condition check
total >= victoryPoints
. - If the condition is met, log a win message in the console:
console.log('You win! Points: ' + total + ', misses: ' + misses)
. - Otherwise log a lose message in the console:
console.log('You lose. Points: ' + total + ', misses: ' + misses)
.
Comments