Home > OS >  Stop int at number 10 when button clicked in HTML
Stop int at number 10 when button clicked in HTML

Time:10-06

    document.getElementById("btn1").onclick = function() 
{
                
                let btn1 = Math.floor(Math.random() * 2   1);
                
                if (btn1 === 1) {
                    span1.innerHTML = parseInt(span1.innerHTML)  1;
}

is it possible to make the span1.innerHTML = parseInt(span1.innerHTML) 1; stop at number 10 when clicked and start at 0 again. If not is there any other way that I can achieve that. I've been researching and trying code for about 3 hours now but in vain, as non of the code I found seems to work for me.

CodePudding user response:

try:

document.getElementById("btn1").onclick = function() {
        
        let btn1 = Math.floor(Math.random() * 2   1);
        
        if (btn1 === 1) {
if(parseInt(span1.innerHTML) < 10)

            span1.innerHTML = parseInt(span1.innerHTML)  1;
}
else
 span1.innerHTML = 0
  • Related