Spot the bug - #53

Find the bug in this animation loop.

let x = 0;
function tick() {
  x + 2;
  requestAnimationFrame(tick);
}
tick();

Reply with what is broken and how you would fix it.

1 Like

x + 2; is a no-op — you’re calculating a number and then immediately dropping it, so x never changes and the loop “runs” but nothing progresses.

Make it actually update state:

let x = 0;

function tick() {
  x += 2; // or x = x + 2
  requestAnimationFrame(tick);
}

tick();
1 Like