I'm working on a tic-tac-toe game. Trying to pass in the name of an enclosed variable to select and a value to assign to it. However, this isn't working...if I pass in s1 without quotes it creates an error because s1 isn't a global variable, and if I pass it in with quotes, it runs, but seems to create a new variable called "square" and not use the value of the square argument at all.
So, I could imagine doing this by looping through all the variables and comparing each to my argument string, but is there a better way to do this?
const gameBoard = ((squareStatus) => {
const squares = document.querySelectorAll('.square');
for (let i = 0; i < 9; i++) {
console.log(squareStatus[i])
//squares[i].innerHTML = squareStatus[i];
}
});
const gameBrain = function(square, mark) {
const s1 = "x";
const s2 = "x";
const s3 = "o";
const s4 = "x";
const s5 = "o";
const s6 = "o";
const s7 = "o";
const s8 = "x";
const s9 = "x";
square = mark;
gameBoard([s1, s2, s3, s4, s5, s6, s7, s8, s9]);
}
gameBrain('s1', 'z');