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 just a math expression that gets thrown away. Nothing ever assigns the new value back into x, so it stays 0 forever.
Fix is to actually mutate x:
let x = 0;
function tick() {
x += 2; // or: x = x + 2
requestAnimationFrame(tick);
}
tick();
:: Copyright KIRUPA 2024 //--