To keep the example as simple as possible, this will be a single level of Tetris that will reset after a game over state has been achieved. Let's get started.
Step 0. Define a few variables
You can never have too many variables. A motto to code by. This isn't 1950, so memory is more than plentiful. Sometimes a single variable declaration can change the shape of your entire codebase. Here are all the variables that were defined in the making of this game.
var shapes = new Array();
var height = 15;
var width = 10;
var state = 1; // 1 running - 0 paused - 2 game over
var colors = ['black', 'orange', 'red', 'blue'];
var move = 0;
var occupiedblocks = new Array();
var direction = "";
var points = 0;
Step 1. Make the Tetris game board
. . .