Codington
0 of 10 problems solved • 0%

Exercise prompt

Trace an Array Total

An accumulator can combine values while a loop visits an array. It starts before the loop and changes once for each item.

Example

const prices = [4, 6]; let total = 0; for (const price of prices) { total += price; } console.log(total); // outputs 10

Predict 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); }
What will this code print?