When i console.log the winConditions array it shows all zeroes when its supposed to have some 1’s in it aswell.
I’m changing the value of a, b and c at the click event listener but idk why they are not changing
Someone please help me
let a = 0,
b = 0,
c = 0,
d = 0,
e = 0,
f = 0,
g = 0,
h = 0,
i = 0;
const test = document.querySelector(".gameboard");
test.addEventListener("click", () => {
a = 1;
b = 1;
c = 1;
gameBoard.applyWinConditions;
console.log(gameBoard.winConditions)
gameBoard.gameFlow.checkScore();
});
const gameBoard = (() => {
let gameBoard = {};
let 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]];
return gameBoard.winConditions;
}
const gameFlow = (function() {
const _isEveryElementOne = (arr) => {
return arr.every(el => el === 1)
}
const _announceWinner = () => console.log("game ends");
return {
checkScore: () => {
console.log(gameBoard.winConditions);
if (gameBoard.winConditions.some(cond => _isEveryElementOne(cond))) return _announceWinner()
console.log("game continues")
},
};
})();
return {
gameFlow,
applyWinConditions: applyWinConditions(),
winConditions: gameBoard.winConditions,
}
})();
gameBoard.applyWinConditions;
console.log(gameBoard.applyWinConditions)