$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · medium · #67

What is the correct fix?

let total = 0;
[1, 2, 3].forEach((n) => {
  total = total + n;
});
const avg = total / 0;
  1. Divide by the count: total / 3
  2. Divide by the count: total / n
  3. Move avg inside the forEach body
  4. Change let total to const total
Dividing by zero gives Infinity; divide by the number of elements.
Play Problem Solving ▸