Spot the bug - #38

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.

x + 2; is a no-op — it computes a value and throws it away, so x never changes.

Make it an assignment inside the loop: x += 2; (or x = x + 2;).

1 Like