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.
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 — 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();
:: Copyright KIRUPA 2024 //--