CodeAgeBy Sitezack
Final project: your TetrisTetris on Canvas, inside a real website0 XP
Chapter progress0/6

Lesson 1 of 6

The game grid

Every Tetris rests on a grid: an array of rows, each row an array of cells (0 = empty, 1 = filled).

Classic trap: every row must be a FRESH array. If all rows share the same array, filling one cell fills them all!

function makeGrid(rows, cols) {
  var grid = [];
  for (var r = 0; r < rows; r++) {
    var row = [];
    // fill row with 0s, then grid.push(row)
  }
  return grid;
}

🎯 Your goal

Write the makeGrid(rows, cols) function that returns a grid of rows lines × cols columns filled with 0s — with a fresh array for every row.

PRO lesson

This advanced chapter is part of CodeAge PRO. Unlock it to keep your adventure going.

Discover PRO