Quotes help make search much faster. Example: "Practice Makes Perfect"

Sunday, December 9, 2012

Codecademy: Codeyear Base case, Recursive case


//sample solution


function factorial(n) {
  // This is our Base Case - when n is equal to 0, we stop the recursion
  if (n === 0) {
    return 1;
  }
 
  // This is our Recursive Case
  // It will run for all other conditions except when n is equal to 0
  return n * factorial(n - 1);
}

factorial(5);

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts