why is it console.logging the array with all zeroes??
im clearly changing value but its still console.logging with just zeroes
let a = 0,
b = 0,
c = 0,
d = 0,
e = 0
f = 0,
g = 0,
h = 0,
i = 0;
const test = document.querySelector(".test");
test.addEventListener("click", () => {
a = 1;
b = 1;
c = 1;
gameBoard.winConditions;
console.log(gameBoard.winConditions)
})
const gameBoard = {
winConditions: [[a, b, c], [a, d, g], [a, e, i], [b ,e, h], [c, e, g],
[c, f, i], [d, e, f], [g, h, i]]
}
gameBoard.winConditions; this line does nothing. When updating the a,b,c... variables, the winConditions stay the same. I would recommend to write a function to re-evaluate the value of winConditions:
let a = 0,
b = 0,
c = 0,
d = 0,
e = 0
f = 0,
g = 0,
h = 0,
i = 0;
const test = document.querySelector(".test");
test.addEventListener("click", () => {
a = 1;
b = 1;
c = 1;
applyWinConditions();
console.log(gameBoard.winConditions)
})
const gameBoard = {};
applyWinConditions(); // set the win conditions initially
function applyWinConditions() {
gameBoard.winConditions = [[a, b, c], [a, d, g], [a, e, i], [b ,e, h], [c, e, g], [c, f, i], [d, e, f], [g, h, i]];
}