var array = [5,4,3,2,1];
document.write("<br>Facorial: " + factorial(array));
//factorial function Ex. 5! = 5*4*3*2*1 = 120
function factorial(params){
var f = 1;
for (i = 0; i <= params.length; ++i){
for (j = 1; j <= params[i]; j++){
f = f * params[j];
}
}
return f;
}
I'm trying to make a program where the user inputs a bunch of random numbers in an array and the program calculates different things about those numbers.
I'm trying to have each individual number within my array be factorialed and then presented in the same form.
How I have it right now I'm getting NaN for my output.
What am I doing wrong? Or am I maybe not doing enough?
CURRENT OUTPUT
Factorial: NaN
WHAT I WANT
Factorial: 120,24,6,2,1