What is the correct fix?
let total = 0;
[1, 2, 3].forEach((n) => {
total = total + n;
});
const avg = total / 0;
- Divide by the count:
total / 3 - Divide by the count:
total / n - Move
avginside the forEach body - Change
let totaltoconst total
Dividing by zero gives Infinity; divide by the number of elements.
Play Problem Solving ▸