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.

11th Dec 2018, 2:05 PM
Tahiro Ab
Tahiro Ab - avatar
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
11th Dec 2018, 4:17 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 6
You mean factorial
11th Dec 2018, 2:11 PM
Rstar
Rstar - avatar
+ 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
11th Dec 2018, 2:15 PM
Rstar
Rstar - avatar
+ 6
Yes it can be done. But in my code I have done it by recursion
11th Dec 2018, 2:18 PM
Rstar
Rstar - avatar
11th Dec 2018, 2:21 PM
Rstar
Rstar - avatar
+ 2
Thanks a lot... So it can't be done using loops right?
11th Dec 2018, 2:16 PM
Tahiro Ab
Tahiro Ab - avatar
0
Yeah... That's what is called?
11th Dec 2018, 2:15 PM
Tahiro Ab
Tahiro Ab - avatar