Script
Script
play-board");
let setIntervalId;
let score = 0;
clearInterval(setIntervalId);
location.reload();
velocityX = 0;
velocityY = -1;
velocityX = 0;
velocityY = 1;
velocityX = -1;
velocityY = 0;
velocityX = 1;
velocityY = 0;
// Calling changeDirection on each key click and passing key dataset value as an object
updateFoodPosition();
localStorage.setItem("high-score", highScore);
scoreElement.innerText = `Score: ${score}`;
snakeX += velocityX;
snakeY += velocityY;
// Shifting forward the values of the elements in the snake body by one
snakeBody[0] = [snakeX, snakeY]; // Setting first element of snake body to current snake position
// Checking if the snake head hit the body, if so set gameOver to true
gameOver = true;
playBoard.innerHTML = html;
updateFoodPosition();