Build a total
Take your time, follow the code and check your understanding.
Move blocks into orderLoops
console.log(total);
}
total += n;
for (const n of [1, 2, 3]) {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);