dimanche 4 mars 2018

simple condition not using isNan?

I am adding input a and input b, and if there is no selected input in the html, this alert returns 'nan', and I am trying to use an if statement to catch the 'nan' and under that condition, print a different message if they did not enter a number, but called the function (clicked the button)

function add(a, b) {
    var sum = parseInt(a) + parseInt(b);
    if(isNan(sum) === false){
        alert('please enter an integer');
    }
    alert(sum);
}

Aucun commentaire:

Enregistrer un commentaire