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 — it calculates a value and then immediately tosses it, so x never changes.
Fix is just making it an assignment: x += 2; (or x = x + 2;) inside tick() so it actually increments every frame.
:: Copyright KIRUPA 2024 //--