Answer the question
In order to leave comments, you need to log in
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question