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

Which fix removes the bug?

const items = ['a', 'b', 'c'];
for (let i = 0; i <= items.length; i++) {
  console.log(items[i].toUpperCase());
}
  1. Change <= to <
  2. Start the index at 1
  3. Use items.length - 1
  4. Guard with a try block
The final iteration reads index 3, which is undefined, so the method call throws.
Play Problem Solving ▸