Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var factorial = function(n) {
- var result = 1;
- for(var i= 1 ; i<= n; i++){
- result= result *i;
- }
- return result;
- };
- println("The value of 5! should be " + 5*4*3*2*1);
- println("The value of 5! is " + factorial(5));
- println("The value of 0! should be 1");
- println("The value of 0! is " + factorial(0));
- Program.assertEqual(factorial(5), 120);
- Program.assertEqual(factorial(0), 1);
- Program.assertEqual(factorial(2), 2);
- Program.assertEqual(factorial(4), 24);
Add Comment
Please, Sign In to add comment