I was following a “The Coding Train” video on how to code minesweeper in js
It was for my school project, but I had one problem, first I am a new programmer
I was following then I got the “uncaught (in promise) TypeError: cannot set properties of undefined (setting ‘0’) on line 22, column 24
My code is:
var grid;
var cols;
var rows;
var w = 20;
function make2DArray(cols, rows) {
var arr = new Array(cols);
arr = [];
for (var i = 0; i < arr.length; i++) {
arr[1] = new Array(rows);
}
return arr;
}
function setup() {
createCanvas(200, 200);
cols = floor(width / w);
rows = floor(height / w);
grid = make2DArray(cols, rows);
for (var i = 0; i < cols; i++) {
for (var j = 0; j < rows; j++) {
grid[i][j] = new Cell(i * w, j * w, w);
}
}
}
function draw() {
background(0);
for (var i = 0; i < cols; i++) {
for (var j = 0; j < rows; j++) {
grid[i][j].show();
}
}
}
I tried adding “for (var j = 0; j < arr.width; j++) under the integer variable in “make2DArray” and expecting it to work just like how the tutorial did