An accumulator can combine values while a loop visits an array. It starts before the loop and changes once for each item.
const prices = [4, 6];
let total = 0;
for (const price of prices) {
total += price;
}
console.log(total); // outputs 10Predict the output
A scoreboard reports its running total after each round. Predict all three lines.
const points = [3, 5, 2];
let total = 0;
for (const point of points) {
total += point;
console.log("Total:", total);
}