OneBug This week's bugs
Spot the bug JavaScript
1
// Average the answered scores; blank cells import as "".
2
const scores = [4, "", 5, 0, 3];
3
let sum = 0;
4
let answered = 0;
5
for (const s of scores) {
6
  if (s == "") continue;
7
  sum += s;
8
  answered += 1;
9
}
10
const avg = Math.round((sum / answered) * 100) / 100;
11
console.log(avg);
12
// expected: 3
13
// actual:   4  (!)

Read the full write-up for this bug (spoilers)