lundi 28 octobre 2019

JS Changing a global variable from within an if-function for a new result [duplicate]

This question already has an answer here:

I'm trying to stray an inch from guided tutorials with something simple, but I don't understand what I'm doing wrong. why isn't the if-statement changing the value of paused?

<body>
  <a href="#" class="btn" onclick="initiative()"> Play!</a>
  <p id="demo"></p>
</body>

<script>
  paused = 0;

function initiative() {
    if (paused = 0){
        var paused = 1;
        document.getElementById("demo").innerHTML = "currently: " + paused;
    } else if (paused = 1){
        var paused = 0;
        document.getElementById("demo").innerHTML = "currently: " + paused;
    } else {
    document.getElementById("demo").innerHTML = "This isn't supposed to be: " + paused;
    }

}

I'm hoping to click on my btn to get a 1 and the next time a 0 and to continue alternating.

The output I keep getting is 0.

Aucun commentaire:

Enregistrer un commentaire