Last active
December 9, 2015 16:44
-
-
Save joePichardo/7131df861d5e552cb22f to your computer and use it in GitHub Desktop.
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: @joepichardo | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-factorialize-a-number | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function factorialize(num) { | |
if(num === 0){ | |
return 1; | |
} | |
var newNum = num; //make new variable so there is no infinite for loop | |
//for loop starts at 1 and multiplies until it reaches num | |
for(var i = 1; i < num; i++){ | |
newNum = newNum * i; | |
} | |
num = newNum; | |
return num; | |
} | |
factorialize(5); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment