S
S
shemshen2021-06-14 18:15:56
JavaScript
shemshen, 2021-06-14 18:15:56

Factorial through an array. null==0? Convert string to number (NaN)?

An attempt to calculate factorial through an array.

Is it enough to specify a comparison with zero in the first if so that null is also taken into account when canceling input in prompt?

If the prompt value cast to a number contains a string without a number and should be NaN, why doesn't else if work?

let q=+prompt("Введите целое положительное число");
if (q<=0){
alert("Вы ввели неправильные данные");
}
else if(q==NaN){
alert("Вы ввели не число");
}
else{
function fqt(){
let Arr=[];
if (q==1){
alert(q);
}
else{
for(i=1;i<q;i++){
Arr[i-1]=i;
};
let rez=q*Arr.reduce((fqt1,cur)=>fqt1*cur);
alert (rez);
};
};
fqt();
};

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2021-06-14
@Aetae

NaNequal to nothing, not even to himself. Check for : (Not to be confused with simply - which checks not for , but for the fact that the passed value is not converted to a number.=\) NaN === NaN // false
NaNNumber.isNaN().isNaNNaN

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question