Build a total

Take your time, follow the code and check your understanding.

Move blocks into orderLoops
  1. console.log(total);
  2. }
  3.   total += n;
  4. for (const n of [1, 2, 3]) {
  5. let total = 0;
Your answer3 min · no timer

Drag blocks, or use the arrow buttons. Keep the displayed indentation. This task uses the taught sequence; other equivalent programs may also be valid.

Show solution and explanation

Initialise before the loop, update inside it, then print after it.

let total = 0;
for (const n of [1, 2, 3]) {
  total += n;
}
console.log(total);