Master programming syntax, solve interactive challenges & run live code in Syntaxis Explore Arena →
Beginner · 15 XP

Fix Async Closure Loop Bug

The provided function is intended to create an array of timer callbacks that print indices 0 through 4. However, due to `var` function-scoping, every callback prints `5`. Fix the code so that each callback retains its respective loop index `0, 1, 2, 3, 4`.

Show Step-by-Step Hint
  • • Consider the scoping difference between `var` and `let`.
  • • In ES6, `let` creates a new binding for each loop iteration.
Type: Bug Fix
Runtime: JAVASCRIPT
JAVASCRIPT solutionCHALLENGE #2
Solutions and scores are stored in your private attempt history.Sign in to submit challenge