I’m trying to get a button to change from one of three states to another in Javascript.
This is not working.
I’m using the following
function button1() {
if (butt1 = "Blank") {
butt1 = "O"
row1[0].innerHTML = "O"
console.log("O")
sleep(1000)
} else if (butt1 = "O") {
butt1 = "X"
row1[0].innerHTML = "X"
console.log("X")
sleep(1000)
} else if (butt1 = "X") {
butt1 = "O"
row1[0].innerHTML = "O"
console.log("O")
sleep(1000)
}
}
But I can only get the button to change from "Blank" to "O", after which point I get stuck on "O".
Would Anybody be able to give advice on how I can fix this?
Thanks for reading.
{Edit: I know it’s not very pretty or efficient but it’s all that I’ve come up with so far.}
>Solution :
Use assignment operator === in place of = in if conditions