Forked from anonymous/bonfire-factorialize-a-number.js
Created
December 3, 2015 19:06
-
-
Save robertsheacole/4dd0c508d0d98862e86f to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/robertsheacole 's solution for Bonfire: Factorialize a Number
This file contains 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
// Bonfire: Factorialize a Number | |
// Author: @robertsheacole | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-factorialize-a-number | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function factorialize(num) { | |
//Check is num paramater is equal to 0. If so return 1, otherwise answer will be 0. | |
if(num === 0){ | |
return 1; | |
} | |
//This is the main part of the function. It multiplies the paramater by the function paramater minus 1. So, (5 * (5 - 1)) | |
return num * factorialize(num - 1); | |
} | |
factorialize(5); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment