Build a Snake game in JavaScript

This practical course hones your JavaScript skills by building the classic Snake 3310 game. It’s great for those with a basic understanding of HTML, CSS and JavaScript who want to practice by building a project to add to their professional portfolio.


Avatar of Ania Kubow

Duration
99 min

Intermediate
TierFree
Follow
Start Course
Content
About
Introduction: Snake Game
Setting up our HTML
Adding CSS to our Snake Game
Picking out elements using document.querySelector()
Adding squares into our grid using JavaScript
Drawing the Snake on the grid
Using .pop() to remove the tail of our Snake
Using .unshift() to add a square to the direction of our Snake
Using .setInterval() to move our Snake on a time loop
KeyCodes
keyCode Update
Using .addEventListener() to listen out for key presses
Changing our Snake's direction
Google Challenge
Explaining Modulus
Using Modulus in our game
A quick lesson in refactoring
Generating random numbers
Pseudo-coding the Logic of Snake eating an Apple
Removing the Apple
Growing our Snake using .push()
Adding the score using the increment operator
The textContent Google Challenge Results
Speeding up our Snake
Implementing functionality to our Start Button
Implementing Restart Logic
Restarting our Game Code
Wrap up & What's next?
Certificate of Completion