0
Please, I need help on how to solve factorial with for loop in Javascript.
Finding factorial
5 Answers
+ 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
+ 1
function testFactorial(a) {
var x=1;
  for(i=1; i<5; i++){
    console.log(x=x*i);
  }
  x*=2;
return x;
}
+ 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