When I hit a square, the computer picks another square. However, sometimes the computer picks square that is already picked. I think it is because the square is not set.
function fillBox(x) {
if (key == “e”) {
key = “X”;
console.log(key); //Object.values(key)=“X”;
document.getElementById(x).innerHTML = “X”;
compMove();
} else {
alert(“Spot is taken. Try Again”);
}
}
function compMove() {
var loop1 = true;
while (loop1) {
var x = Math.floor(Math.random() * 9);
var y = Object.values(key);
if (y == “e”) {
key=“O”;
Object.values(key) = “O”;
document.getElementById(Object.keys(key)).innerHTML = “O”;
loop1=false;
}
}
}