Skip to content

Instantly share code, notes, and snippets.

@Neodevils
Created October 23, 2022 12:07
Show Gist options
  • Save Neodevils/4ce56e6ae68ea3b32d061ec39c64e46c to your computer and use it in GitHub Desktop.
Save Neodevils/4ce56e6ae68ea3b32d061ec39c64e46c to your computer and use it in GitHub Desktop.
Factorial
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