how do i reset the state of the board after a tictactoe game?
i want to fire the startGame() function where it will clear out all the x's and O's of the board whenever i hit the restart button.
or do you have any other cleaner approach to do so? thank you so much
const squares = document.querySelectorAll('.grid')
const XCLASS = "x"
const OCLASS = "o"
const textElementWin = document.getElementById('xowinMessage')
const screenElementWin = document.querySelector('.winningScreen')
const textElementDraw = document.getElementById('drawMessage')
const screenElementDraw = document.querySelector('.drawScreen')
const restartButtons = document.querySelectorAll('.button')
const winCombinations=[
[0,1,2],
[3,4,5],
[6,7,8],
[0,3,6],
[1,4,7],
[2,5,8],
[0,4,8],
[2,4,6]
]
let circleturn
squares.forEach(square => {
square.addEventListener('click', handleEvent, {once:true})
})
function handleEvent(event){
const cell = event.target
const currentPlayer = circleturn ? OCLASS : XCLASS
placeItem(cell,currentPlayer)
if (checkWin(currentPlayer)){
screenElementWin.classList.add('show')
textElementWin.innerText = `${currentPlayer} wins!`
}else if(checkDraw()){
screenElementDraw.classList.add('show')
textElementDraw.innerText = "It's a tie!"
}
else{
swapTurn()
}
}
restartButtons.forEach(eachbutton => {
eachbutton.addEventListener('click', ()=>{
screenElementWin.classList.remove('show')
startGame()
})
})