I’m having some trouble with Ania Kubow’s Javascript Tetris Tutorial (https://www.youtube.com/watch?v=rAUn1Lom6dw)
I’m trying to add a blue color to a couple of divs to create a L shape tetris piece but am having problems with the function;
function draw() {
current.forEach((index) => {
squares[currentPosition + index].classList.add("tetromino");
});
}
draw();
Uncaught TypeError: Cannot read property 'classList' of undefined
at app.js:59
at Array.forEach (<anonymous>)
at draw (app.js:58)
at app.js:63
these are my error msgs >:(
on the video it is around the 42 min mark
Any help greatly appreciated
Here is the rest of my JS code
const grid = document.querySelector(".grid");
let squares = Array.from(document.querySelectorAll(".grid div"));
const ScoreDisplay = document.querySelector("#score");
const StartButton = document.querySelector("#start-button");
const width = 10;
//the tetrominoes
const lTetromino = [
[1, width + 1, width * 2 + 1, 2],
[width, width + 1, width + 2, width * 2 + 2],
[1, width + 1, width * 2 + 1, width * 2],
[width, width * 2, width * 2 + 1, width * 2 + 2],
];
const zTertrmino = [
[0, width, width + 1, width * 2 + 1],
[0, 1, width + 1, width + 2],
[0, width, width + 1, width * 2 + 1],
[0, 1, width + 1, width + 2],
];
const tTetromino = [
[width, 1, width + 1, width + 2],
[1, width + 1, width * 2 + 1, width + 2],
[width, width + 1, width + 2, width * 2 + 1],
[1, width, width + 1, width * 2],
];
const oTetromino = [
[0, 1, width, width + 1],
[0, 1, width, width + 1],
[0, 1, width, width + 1],
[0, 1, width, width + 1],
];
const iTetromino = [
[1, width + 1, width * 2 + 1, width * 3 + 1],
[width, width + 1, width + 2, width + 3],
[1, width + 1, width * 2 + 1, width * 3 + 1],
[width, width + 1, width + 2, width + 3],
];
const theTetrominos = [
lTetromino,
zTertrmino,
tTetromino,
oTetromino,
iTetromino,
];
let currentPosition = 4;
let current = theTetrominos[0][0];
//draw first rotation
function draw() {
current.forEach((index) => {
squares[currentPosition + index].classList.add("tetromino");
});
}
draw();