Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Javascript If statement not having correct result

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

{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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading