# Spot the bug - #147: Moving Sprite Position

**URL:** <https://forum.kirupa.com/t/spot-the-bug-147-moving-sprite-position/683387>\
**Category:** web dev\
**Created:** [September 17, 2026, 7:00am UTC](https://forum.kirupa.com/t/spot-the-bug-147-moving-sprite-position/683387 "2026-09-17T07:00:07Z")\
**Posts on this page:** 4\
**Page:** 1

<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:** [September 17, 2026, 7:00am UTC](https://forum.kirupa.com/t/spot-the-bug-147-moving-sprite-position/683387/1 "2026-09-17T07:00:07Z")

</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:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [September 18, 2026, 12:34am UTC](https://forum.kirupa.com/t/spot-the-bug-147-moving-sprite-position/683387/2 "2026-09-18T00:34:03Z")

</div>

This is a repeat. No incrementer in `x + 2`. It should be `x += 2`.

---

<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:** [October 1, 2026, 8:00pm UTC](https://forum.kirupa.com/t/spot-the-bug-147-moving-sprite-position/683387/3 "2026-10-01T20:00:08Z")

</div>

**Spot the Bug answer:** The ‘x’ variable is not being updated because the result of the addition is not assigned back to it.

**The fix:**  
x += 2;

**Why:**  
In JavaScript, the expression ‘x + 2’ calculates a new value but does not modify ‘x’ itself. To update ‘x’, the result of the addition must be assigned back to ‘x’, either with ‘x = x + 2’ or the shorthand ‘x += 2’.

* * *

**Got it:** @kirupa 🏆

**First-answer leaderboard**

1. @kirupa - 7 (firsts) 🏆
2. @Apexcodes - 6 (firsts)
3. @emmawalter5 - 6 (firsts)
4. @adnanahmed - 2 (firsts)

---

<div class="post-metadata">

**Author:** ![Ellen1979](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ellen1979/32/31260_2.png) [@Ellen1979](https://forum.kirupa.com/u/Ellen1979)\
**Post date:** [October 2, 2026, 1:00am UTC](https://forum.kirupa.com/t/spot-the-bug-147-moving-sprite-position/683387/4 "2026-10-02T01:00:20Z")

</div>

Yeah this is a classic. seen it cause more than a few headaches with junior devs on my team.
