Skip to content

Instantly share code, notes, and snippets.

@joePichardo
Last active December 9, 2015 16:44
Show Gist options
  • Save joePichardo/7131df861d5e552cb22f to your computer and use it in GitHub Desktop.
Save joePichardo/7131df861d5e552cb22f to your computer and use it in GitHub Desktop.
Factorialize a Number
// 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