I am trying to draw rectangles that represent walls on javascript html canvas. My question here is why doesn't it recognized walls[i].length?
canvas = document.getElementById("myCanvas")
context = canvas.getContext('2d')
var boxSize = 40
var wallsCoordinates = [[3,2][3,3],[3,4]]
function drawWalls(walls) {
context.fillStyle = "grey"
for(var i = 0; i < walls.length; i++) {
for(var j = 0; j < walls[i].length; j += 2)
context.fillRect(walls[i][j] * boxSize, walls[i][j + 1] * boxSize,
boxSize, boxSize)
}
}
drawWalls(wallsCoordinates)
walls[i].length. What exactly is the problem? Note that your code will go 1 element beyondwalls[i]because of thatj + 1.var wallsCoordinates = [[3,2],[3,3],[3,4]]