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; doesn’t mutate anything — it just evaluates and throws the result away, so x stays 0 forever.
Change it to an assignment, e.g. x += 2; (or x = x + 2;) inside tick() so the loop actually advances state.
:: Copyright KIRUPA 2024 //--