Created
October 23, 2022 12:07
-
-
Save Neodevils/4ce56e6ae68ea3b32d061ec39c64e46c to your computer and use it in GitHub Desktop.
Factorial
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function factorial(n) { | |
let answer = 1; | |
if (n == 0 || n == 1) { | |
return answer; | |
} else { | |
for (var i = n; i >= 1; i--) { | |
answer = answer * i; | |
} | |
return answer; | |
} | |
} | |
let n = 4; | |
answer = factorial(n); | |
console.log("The factorial of " + n + " is " + answer); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment