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.


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.

yes thankfully. forgot to add snake class.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.