diff --git a/calculator/calculator.js b/calculator/calculator.js index 8ad98c0..660e58a 100644 --- a/calculator/calculator.js +++ b/calculator/calculator.js @@ -19,9 +19,20 @@ function power(a, b) { } function factorial(n) { + if (n == 0) return 1; + let product = 1; + for (let i = n; i > 0; i--) { + product *= i; + } + return product; +} + +// This is another implementation of Factorial that uses recursion +// THANKS to @ThirtyThreeB! +function recursiveFactorial(n) { if (n===0){ return 1; -} + } return n * factorial (n-1); }