vendredi 19 février 2021

Hi, all. I got into a beginner-js problem

I would like to create 2 buttons one of which increases a number and the other decreases it, and I did do it. The problem is I don't want the numbers to go higher than 10 or lower than 0, I tried if else but didn't work. Can you, please, help me?

Here is the code:

document.addEventListener("DOMContentLoaded", function () {
    document.querySelector('#add').onclick = adding
    document.querySelector('#minus').onclick = subtracting
})

let counter = 0
function adding() {
    counter++
    document.querySelector('h1').innerHTML = counter

}


function subtracting() {
    counter--
    document.querySelector('h1').innerHTML = counter
    if( counter < 1){
        document.getElementById('minus').disabled = true
    } else{
        document.getElementById('minus').disabled = false
    }

}

Aucun commentaire:

Enregistrer un commentaire