I’ve been learning Javascript over the last month as part of the Flatiron Software Engineering program. My love-hate relationship with Javascript has gone more towards the love side as I’ve gotten a better understanding of its quirks. For example, understanding hoisting and that Javascript separates compilation and execution at runtime goes a long way towards being able to understand some of the nasty bugs (or silent fails) that Javascript will throw if I don’t structure my code well.

For my Javascript/Rails API portfolio project, I decided to build the classic game, Tetris (play it live here or checkout the github repo!). My other portfolio projects have been CMSs of one form or another. I wanted to build something more fun. Tetris has also been a good way for me to delve into some of the aspects that make Javascript unique, like DOM manipulation and event handling in the browser.

Screenshot of Tetris webpage

Screenshot of Tetris

Most of the project went swimmingly. I began by representing the Tetris board with a 12×24 nested array and displaying the board on the DOM with a table element. I built out separate classes to represent cells and pieces, and built child classes of the Piece class to represent the different types of pieces. Along the way, I came across two main challenges:

#software-engineering #javascript #beginner #single-responsibility #asynchronous

Building Tetris in JS — The Rotation Problem and Asynchronous Functions
2.95 GEEK