Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function factorial(num)
- {
- // If the number is less than 0, reject it.
- if (num < 0) {
- console.log('use a number above 1');
- return -1;
- }
- // If the number is 0, its factorial is 1.
- else if (num == 0) {
- return 1;
- }
- let tmp = num;
- while (num-- > 2) {
- tmp *= num;
- }
- return tmp;
- }
- let result = factorial(18);
- console.log(result);
- // Output: 6402373705728000
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement