I'm trying to access the object behind the click in the console, it return the image instead, and I want to alter that object properties which makes it impossible, how do I access the object itself and not the image sitting on it?
For example if I type in the console gBoard[0][0]
it return the image itself(aka TILE), I want to access the cell object that's behind it.
I would appreciate an explanation and a proper console log for it.
const TILE ='<img src="/img/tile.png" >'
function cellClicked(elCell, i, j) {
// if (!gGameInterval) return;
console.log('Click', i, j);
// debugger
if(gBoard[i][j].isBomb===true){
gBoard[i][j].isFlagged=true
elCell.innerHTML=TWO
}
}
function printMat(mat, selector) {
var strHTML = '<table border="1"><tbody>';
for (var i = 0; i < mat.length; i++) {
strHTML += '<tr>';
for (var j = 0; j < mat[0].length; j++) {
var cell = mat[i][j]=TILE
var className = `cell-${i}-${j}`
strHTML +=
`<td class="${className}"
onclick="cellClicked(this, ${i}, ${j})">
${cell}
</td>`
}
strHTML += '</tr>'
}
strHTML += '</tbody></table>';
var elContainer = document.querySelector(selector);
elContainer.innerHTML = strHTML;
}
function createBoard(size) {
var board = []
for (var i = 0; i < size; i++) {
board[i] = []
for (var j = 0; j < size; j++) {
board[i][j] = creatCell()
}
}
return board
}
function creatCell() {
return {
isBomb: false,
isFlagged: false,
isClicked: false,
isOpen: false
}
}