Spot the bug - #66

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; doesn’t do anything — it calculates a number and tosses it, so x stays 0 forever.

Change it to x += 2; (or x = x + 2;) inside tick(), and then use x to update your DOM/canvas state before scheduling the next frame.