178
rated 0 times
[
185]
[
7]
/ answers: 1 / hits: 56177
/ 9 Years ago, wed, june 3, 2015, 12:00:00
I am trying to make a factorial calculator. How can I check if the input is empty or not? I tried 'null'. But it didn't work or I couldn't use it properly.
sorry for the stupid question. I am newbie in JavaScript
function myFriday() {
var input = document.getElementById(input1).value;
var ever = function () {
if( !(isNaN(input))) {
var result = 1;
for(var i = 1; i <= input; i++ ) {
result = result * i
}
return result;
}
else if (input == null){
return Please input a number
}
else{
return Please input a number
}
}
document.getElementById(input2).value = ever();
}
<p>Input: <input type=text id = input1 /></p>
<p>Input: <input type=text id = input2 /></p>
<button onclick = myFriday()>Calculate</button>
<p >RESULT: <span id = result style = color:red></span> </p>
More From » javascript