dimanche 23 octobre 2016

How do I use if and condition for checking if two variables are number

So this is a simple program to print a multiplication table of user input number upto user input range. I also included a if condition in order to check if inputs are numbers. SO I used isNaN(a) && isNaN(b) in if condition which is wrong I guess. How do I properly do it? Please no other methods...

function theTable(){
var a = Number(document.getElementById('number').value);
var d = Number(document.getElementById('range').value);
var c = "";

if ((isNaN(a)) && (isNaN(d)) ){
    document.getElementById('answer').innerHTML = "Input is not a number";
}else{
        for(i=1; i<=d; i++){
        var b = a + "x" + i + "=" + (a*i);
        var c = c + b + "<br />";
    }   
    document.getElementById('answer').innerHTML = c;
}   

}

Aucun commentaire:

Enregistrer un commentaire