There is good advice in the answer by adrianton3. I noticed one other thing:
You may have already updated the structure of the board based on adrianton3's answer but instead of this:
let gameboard = []; // = ["*", "*", "*", "*", "*", "*", "*", "*", "*"];
let symbol = "*";
for (let i = 0; i < 9; i++) {
gameboard[i] = symbol;
}
it could be simplified to use Array.fill()
:
const symbol = "*";
const gameboard = Array(9).fill(symbol);
That way there is no need to loop through the board when initializing the default values.
It likely won't be an issue when users input numbers 0-9 but something to be aware of is that calls to parseInt()
without a radix
parameter may yield unexpected results if the input happens to contain a leading zero (or else hex prefix: 0x
). See this post for more information.