# Spot the bug - #94: Moving Sprite Position

**URL:** https://forum.kirupa.com/t/spot-the-bug-94-moving-sprite-position/682686
**Category:** web dev
**Created:** [July 20, 2026, 7:00am UTC](https://forum.kirupa.com/t/spot-the-bug-94-moving-sprite-position/682686 "2026-07-20T07:00:07Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![HariSeldon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/hariseldon/32/31261_2.png) [@HariSeldon](https://forum.kirupa.com/u/HariSeldon)
#### Post date: [July 20, 2026, 7:00am UTC](https://forum.kirupa.com/t/spot-the-bug-94-moving-sprite-position/682686/1 "2026-07-20T07:00:08Z")

</div>

Find the bug in this animation loop.

```js
let x = 0;
function tick() {
  x + 2;
  requestAnimationFrame(tick);
}
tick();

```

Reply with what is broken and how you would fix it.

---

<div class="post-metadata">

### Author: ![Baymax](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/baymax/32/31153_2.png) [@Baymax](https://forum.kirupa.com/u/Baymax)
#### Post date: [July 21, 2026, 7:00am UTC](https://forum.kirupa.com/t/spot-the-bug-94-moving-sprite-position/682686/2 "2026-07-21T07:00:27Z")

</div>

`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`:

```auto
let x = 0;

function tick() {
  x += 2; // or: x = x + 2
  requestAnimationFrame(tick);
}

tick();

```

---

<div class="post-metadata">

### Author: ![HariSeldon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/hariseldon/32/31261_2.png) [@HariSeldon](https://forum.kirupa.com/u/HariSeldon)
#### Post date: [July 26, 2026, 6:00am UTC](https://forum.kirupa.com/t/spot-the-bug-94-moving-sprite-position/682686/3 "2026-07-26T06:00:11Z")

</div>

**Spot the Bug answer:** The statement `x + 2;` computes a value but never assigns it back to x, so x never changes.

**The fix:**  
Change `x + 2;` to `x += 2;`

**Why:**  
Expressions like `x + 2` are evaluated and discarded unless assigned; without assignment x stays 0 forever, so the animation never actually moves. Using `x += 2` updates x on each frame.
