Why is my snake not increasing after eating food?

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

//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.

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

1 Like