0

Please, I need help on how to solve factorial with for loop in Javascript.

Finding factorial

26th May 2019, 12:33 PM
Odunsi Joseph
Odunsi Joseph - avatar
5 Respostas
+ 16
Odunsi Joseph Sorry,😊 Here is with while loop...👍 function factorial(n) { // A variable that holds the running value // of factorial during calculation. let factorial = n; // Note that this loop decrements the // value of n during each iteration. while (n-- > 1) { factorial = factorial * n; } return factorial; } console.log( factorial(5) ); • https://code.sololearn.com/WMt3NCSb4mrO/?ref=app
26th May 2019, 1:58 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 1
function testFactorial(a) { var x=1;     for(i=1; i<5; i++){         console.log(x=x*i);     }     x*=2; return x; }
26th May 2019, 1:00 PM
Odunsi Joseph
Odunsi Joseph - avatar
+ 1
~ swim ~ Thank you very much. I was able to solve the problem. The x*=2 in the code is to double the result. Thank you once again
26th May 2019, 2:26 PM
Odunsi Joseph
Odunsi Joseph - avatar