Skip to content

Instantly share code, notes, and snippets.

@jlarocque
Created December 28, 2017 01:56
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 jlarocque/3b529b3e41916eb97b0fea90e44acfac to your computer and use it in GitHub Desktop.
Save jlarocque/3b529b3e41916eb97b0fea90e44acfac to your computer and use it in GitHub Desktop.
First Factorial
<script src='https://scottdalessandro.github.io/jasmine-total/js/jasmine-suite.min.js'></script>
/*
Factorial
Create the function **factorial(num)** that returns the factorial of the parameter.
Not sure what a factorial is? Check [this link](http://www.rapidtables.com/math/algebra/Factorial.htm) for a refresher!
<br>
####Example:
- INPUT: factorial(4);
- OUTPUT: 24
-INPUT: factorial(5);
-OUTPUT: 120
<br>
<hr>
<br>
*/
// Write Code Below
function factorial(num){
var total = 1;
for (num; num > 1; num--){
total *= num;
}
return total;
}
describe('factorial', function(){
it('factorial is a function', function(){
expect(typeof factorial).toEqual('function');
});
it('factorial returns a number value', function(){
expect(typeof factorial(5)).toEqual('number');
});
it('returns the factorial of the number argument', function(){
expect(factorial(5)).toEqual(120);
expect(factorial(7)).toEqual(5040);
expect(factorial(10)).toEqual(3628800);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment