Skip to content

Instantly share code, notes, and snippets.

@Kiwipup
Created September 6, 2018 23:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kiwipup/7bc9988fa9faeb8f33c28c362eeeb1b0 to your computer and use it in GitHub Desktop.
Save Kiwipup/7bc9988fa9faeb8f33c28c362eeeb1b0 to your computer and use it in GitHub Desktop.
First Factorial
function FirstFactorial(num) {
// code goes here
//when num is finally equal to 1 or 0, the function will terminate
if (num === 0 || num === 1){
return 1;
}
/*Multiplies the value of num by it's own value -1 each time this function loops.
The function will call itself over and over again until num is equal to 1.*/
return num * FirstFactorial(num-1);
}
// keep this function call here
FirstFactorial(readline());
@MatthewGidcomb
Copy link

This looks good. Recursion is a good choice for this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment