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 Respostas
+ 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?