$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · easy · #202

Which fix removes the bug?

const total = 0;
for (const n of [1, 2, 3]) {
  total += n;
}
  1. Declare total with let
  2. Use for...in for the loop
  3. Start total at null
  4. Add a return total line
A const binding cannot be reassigned, so += throws a TypeError.
Play Problem Solving ▸