DEV Community 👩‍💻👨‍💻

Cover image for Build the 2048 game in JavaScript
Ania Kubow
Ania Kubow

Posted on • Updated on

Build the 2048 game in JavaScript

In this walkthrough, we make the very popular game 2048 in JavaScript, HTML and CSS! No canvas required! (Now with more accurate subtitles for programmers)

Rules of 2048:
2048 is played on a 4×4 grid, with numbered tiles that slide smoothly when a player moves them using the four arrow keys. Each time you slide, a new tile will randomly appear in an empty spot on the board. Tiles slide as far as possible in the chosen direction until they are stopped by either another tile or the edge of the grid. If two tiles of the same number collide while moving, they will merge into a tile with the total value of the two tiles that collided. The resulting tile cannot merge with another tile again in the same move.

Tools and Software I used in this video:
TabNine By Codota: https://bit.ly/Codota
VSCode: https://bit.ly/VSCode-Editor

By creating this popular game we will learn the following javaScript Methods:

  • querySelector()
  • getElementById()
  • createElement()
  • appendChild()
  • push()
  • Math.floor()
  • Math.random()
  • length
  • innerHTML
  • parseInt()
  • filter()
  • Array()
  • fill()
  • concat()
  • keyCode
  • addEventListener()
  • removeEventListener()
  • setTimeout()
  • clearInterval()
  • setInterval()

If you did like this video, please do Like and Subscribe so I know to make others like this!

I would love to see what you have made so please do share your finished games with me on twitter! My handle is @ania_kubow .

Top comments (5)

Collapse
 
inspiriongames profile image
InspirionGames

Thanks a lot! Using this tutorial I've created my own version and call it "2048 Virus Evolution 🦠" and it is fantastic 😍😍😍🔥🔥 published in Google Play: play.google.com/store/apps/details...

Collapse
 
ania_kubow profile image
Ania Kubow

woooah on google play! Nice one!

Collapse
 
iamnick profile image
Nick

I ve made my own 2048 game too, using Vuejs 3, play2048.app

Collapse
 
sheraza38010239 profile image
Sheraz Ahmad
Collapse
 
deniskot profile image
DenisKot

I've created my own Big money 2048 🤑 Puzzle Game using onlyJS+HTML+CSS!!! Check this out play.google.com/store/apps/details...

👋 New to DEV?

Head over to our Welcome Thread and tell us a bit about yourself!