- script.js
JavaScript
var score = 0;
var total = 0;
while (score > -1) {
score = muffin.getScore();
total += score;
}
console.log(total);
Result
Goalscompleted
Let’s update the loop to track each throw and log its score to the console.
- Add variable
victoryPoints, which will store100, the number of points needed to win. - Replace the loop condition with
total < victoryPointsso it runs until the required score is reached. - In the loop, log in the console the result of the shot from the variable
score.
Comments