# Why is my snake not increasing after eating food?

**URL:** https://forum.kirupa.com/t/why-is-my-snake-not-increasing-after-eating-food/656205
**Category:** Uncategorized
**Created:** [January 11, 2023, 3:30am UTC](https://forum.kirupa.com/t/why-is-my-snake-not-increasing-after-eating-food/656205 "2023-01-11T03:30:05Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![polaryeti](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/polaryeti/32/19283_2.png) [@polaryeti](https://forum.kirupa.com/u/polaryeti)
#### Post date: [January 11, 2023, 3:30am UTC](https://forum.kirupa.com/t/why-is-my-snake-not-increasing-after-eating-food/656205/1 "2023-01-11T03:30:05Z")

</div>

https://codepen.io/pelko/embed/preview/jOpBmPN?default-tabs=js%2Cresult&height=300&host=https%3A%2F%2Fcodepen.io&slug-hash=jOpBmPN

Here’s the full code.

`snakeArr.unshift({ x: snakeArr[0].x + inputDir.x, y: snakeArr[0].y + inputDir.y })`

This is the code to increase the size of snake once it collides with food.

The code above it is working.

`foodSound.play();`

Similarly, the code below it is working

```auto
//change food location

let a = 2; b = 16;
food = { x: Math.round(a + (b - a) * Math.random()), y: Math.round(a + (b - a) * Math.random()) }

```

What went wrong? Please help me fix the issue. There are no errors in console.

---

<div class="post-metadata">

### Author: ![polaryeti](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/polaryeti/32/19283_2.png) [@polaryeti](https://forum.kirupa.com/u/polaryeti)
#### Post date: [January 11, 2023, 3:45am UTC](https://forum.kirupa.com/t/why-is-my-snake-not-increasing-after-eating-food/656205/2 "2023-01-11T03:45:19Z")

</div>

This issue has been fixed, I forgot to add CSS class to snake.

---

<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: [January 11, 2023, 5:36am UTC](https://forum.kirupa.com/t/why-is-my-snake-not-increasing-after-eating-food/656205/3 "2023-01-11T05:36:29Z")

</div>

Are you building this game yourself or following a tutorial? You are making great progress! 🎉

---

<div class="post-metadata">

### Author: ![polaryeti](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/polaryeti/32/19283_2.png) [@polaryeti](https://forum.kirupa.com/u/polaryeti)
#### Post date: [January 11, 2023, 6:39am UTC](https://forum.kirupa.com/t/why-is-my-snake-not-increasing-after-eating-food/656205/4 "2023-01-11T06:39:10Z")

</div>

following tutorial…☹

---

<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: [January 11, 2023, 5:50pm UTC](https://forum.kirupa.com/t/why-is-my-snake-not-increasing-after-eating-food/656205/5 "2023-01-11T17:50:16Z")

</div>

I have creating a snake game on my list of tutorials to work on, and you may be nudging me to bump that closer to the top haha.

---

<div class="post-metadata">

### Author: ![davidoliver](https://avatars.discourse-cdn.com/v4/letter/d/5e9695/32.png) [@davidoliver](https://forum.kirupa.com/u/davidoliver)
#### Post date: [June 10, 2023, 2:01am UTC](https://forum.kirupa.com/t/why-is-my-snake-not-increasing-after-eating-food/656205/6 "2023-06-10T02:01:38Z")

</div>

I love to play snake game. Do you want to upload it on playstore?

---

<div class="post-metadata">

### Author: ![PAEz](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/paez/32/19607_2.png) [@PAEz](https://forum.kirupa.com/u/PAEz)
#### Post date: [June 20, 2023, 6:35pm UTC](https://forum.kirupa.com/t/why-is-my-snake-not-increasing-after-eating-food/656205/7 "2023-06-20T18:35:55Z")

</div>

Did you want to make a snake game?..  
[https://twitter.com/rowancheung/status/1670829363137499137](https://twitter.com/rowancheung/status/1670829363137499137)
