0
JavaScript Loops
Guys... I was wondering how to write a code that executes the product of all the numbers from it upto one. That is if x=6, It calculates 1*2*3*4*5*6 and it gives me the result.
7 Answers
+ 8
// Factorial
const factorial = function(num) {
if (num === 0 || num === 1) {
return 1;
} else {
return num * factorial(num - 1);
}
}
Here you have a task, and several of its solutions, with textual algorithm!đđ
https://code.sololearn.com/WMt3NCSb4mrO/?ref=app
+ 6
You mean factorial
+ 6
Yes it is called factorial and you denote it by
6!
6!=6Ă5Ă4Ă3Ă2Ă1
https://code.sololearn.com/WKWdPb150xY2/?ref=app
+ 6
Yes it can be done.
But in my code I have done it by recursion
+ 6
+ 2
Thanks a lot... So it can't be done using loops right?
0
Yeah... That's what is called?