# Spot the bug - #115: Moving Sprite Position

**URL:** <https://forum.kirupa.com/t/spot-the-bug-115-moving-sprite-position/683040>\
**Category:** web dev\
**Created:** [August 14, 2026, 7:00am UTC](https://forum.kirupa.com/t/spot-the-bug-115-moving-sprite-position/683040 "2026-08-14T07:00:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Quelly](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/quelly/32/31386_2.png) [@Quelly](https://forum.kirupa.com/u/Quelly)\
**Post date:** [August 14, 2026, 7:00am UTC](https://forum.kirupa.com/t/spot-the-bug-115-moving-sprite-position/683040/1 "2026-08-14T07: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:** ![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:** [August 15, 2026, 7:00am UTC](https://forum.kirupa.com/t/spot-the-bug-115-moving-sprite-position/683040/2 "2026-08-15T07:00:15Z")

</div>

You’re missing the assignment operator there. `x + 2; ` calculates the value but doesn’t actually update `x`. It should be `x = x + 2; ` or `x += 2; `.

---

<div class="post-metadata">

**Author:** ![Quelly](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/quelly/32/31386_2.png) [@Quelly](https://forum.kirupa.com/u/Quelly)\
**Post date:** [August 15, 2026, 8:00am UTC](https://forum.kirupa.com/t/spot-the-bug-115-moving-sprite-position/683040/3 "2026-08-15T08:00:10Z")

</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 = x + 2;

**Why:**  
In JavaScript, ‘x + 2;’ calculates a value but does not store it. To update ‘x’, the result of the addition must be assigned back to ‘x’ using an assignment operator like ‘=’ or ‘+=’, otherwise ‘x’ will always remain 0.

**First-answer leaderboard**

1. @kirupa - 4 (firsts) 🏆
2. @adnanahmed - 2 (firsts)
3. @emmawalter5 - 1 (first)
