Why is this returning: Uncaught ReferenceError: winConditions is not defined?
I'm returning winConditions in the function and then I run the function and then console.log(winConditions), why is it not working?
const gameBoard = (() => {
const board = [null, null, null, null, null, null, null, null, null]
let applyWinConditions = () => {
const winConditions = [[board[0], board[1], board[2]], [board[3], board[4], board[5]],
[board[6], board[7], board[8]], [board[0], board[3], board[6]],
[board[1], board[4], board[7]], [board[2], board[5], board[8]],
[board[0], board[4], board[8]], [board[2], board[4], board[6]]];
console.log("e")
return {
winConditions
}
};
applyWinConditions();
console.log(winConditions)
return {
applyWinConditions: applyWinConditions,
}
})();
it seems you are trying to log a variable that is out of scope.
winConditions is defined inside applyWinConditions, thus not available outside, for console.log to see it.
try something like this:
console.log("winConditions", applyWinConditions());
you should see the return of your function, where winConditions has the value you'd expect.