lundi 8 février 2021

How can I correct my "if" statement in JavaScript? [closed]

I just have made this:

 // increase or decrease the time (in minutes) //
increaseBtn.addEventListener("click", function(){        
    count+=10;    
    if (count>=40)
    {
        return false;
    }

    value.innerHTML=count;
});

decreaseBtn.addEventListener("click", function(){        
    count-=10;
    if (count<=-10)
    {
        return false;
    }
    
    value.innerHTML=count;    
});

When I click on "+" button to increase or "-" button to decrease count, I noticed that count stops at 30 or 0 as it's shown in value element. But when I continue clicking on the buttons - count keeps increasing to 70, 80 or more, or decreasing below zero. I don't know why this function keeps changing the value out of the limits 0 and 30. What's wrong?

Aucun commentaire:

Enregistrer un commentaire