I’ve been tasked with creating my own tic tac toe game through coding. While I am relatively new to programming, I have a strong passion for it. At the moment, I've set up a basic function to hide only the "O", leaving only the "X" visible on the grid. It's a work in progress, but I believe starting off this way is a good approach.
However, I've encountered an issue where clicking on a square causes the "O" to randomly disappear. Sometimes it happens after the first click, other times after four clicks. Can anyone shed some light on what might be causing this random behavior?
Below is the function that I'm currently using and how one of the squares is structured in HTML:
function hideO() {
document.getElementById("O" + event.target.id).style.display = "none";
}
<div class="square" >
<button class="1" id="1" onclick="hideO()">
<p class="X1" id="X1">X</p>
<p class="O1" id="O1">O</p>
</button>
</div>