I'm currently working on a game and facing an issue where my "X" gets deleted when clicking twice on the same tile. I am able to move my "X" around, but the double-click deletion is causing trouble. I attempted using booleans but struggle with them. Is there a method to prevent this using booleans or any other approach? I am a beginner learning in school.
var firstClick = false;
var clickedTile = null;
var secondClick = false;
function movePiece(x) {
if (secondClick == true) {
x.innerHTML = clickedTile.innerHTML;
clickedTile.innerHTML = "";
secondClick = false;
clickedTile.style.border = "1px solid black";
clickedTile.style.height = "80px";
clickedTile.style.width = "80px";
} else {
x.style.border = "3px solid red";
x.style.width = "76px";
x.style.height = "76px";
clickedTile = x;
secondClick = true;
}
}
td {
height: 80px;
width: 80px;
text-align: center;
font-size: 300%;
}
table {
margin-left: auto;
margin-right: auto;
}
#title {
text-align: center;
font-size: 300%;
}
<div id="title">Table Game</div>
<table border=1>
<tr>
<td onclick="movePiece(this)">X</td>
<td onclick="movePiece(this)"></td>
</tr>
</table>