Skip to content

Instantly share code, notes, and snippets.

@daronwolff
Created May 20, 2016 16:41
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 daronwolff/c17518170e358eab2886ba60158bb5fc to your computer and use it in GitHub Desktop.
Save daronwolff/c17518170e358eab2886ba60158bb5fc to your computer and use it in GitHub Desktop.
Javascript Factorial function
function factorial(n) {
"use strict";
var result = 1;
while (n > 1) {
result *= n;
console.log(result);
n -= 1;
}
}
factorial(5);
// 5
// 20
// 50
// 120
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment