Created
December 28, 2017 01:56
-
-
Save jlarocque/3b529b3e41916eb97b0fea90e44acfac to your computer and use it in GitHub Desktop.
First Factorial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src='https://scottdalessandro.github.io/jasmine-total/js/jasmine-suite.min.js'></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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