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

Which fix removes the bug?

const nums = [10, 20, 30];
for (const i in nums) {
  console.log(i * 2);
}
  1. Use for (const n of nums) to get values
  2. Use for (const i on nums) to get values
  3. Change i * 2 to i + i in the body
  4. Change const i to let i in the header
for...in yields string keys ('0','1'), so the multiply is wrong; for...of yields the values.
Play Problem Solving ▸