Factorial
Write a function to return the factorial of a number.
Factorial of a number is given by:
n! = n * (n-1) * (n-2) * ..... * 1
For example:
3! = 3 * 2 * 1 = 6
4! = 4 * 3 * 2 * 1 = 24
Note: 0! = 1
Test
{{test}}Console output
Write a function to return the factorial of a number.
Factorial of a number is given by:
n! = n * (n-1) * (n-2) * ..... * 1
For example:
3! = 3 * 2 * 1 = 6
4! = 4 * 3 * 2 * 1 = 24
Note: 0! = 1
Use Cmd instead of Ctrl if you're on a Mac.
g | Focus editor |
Ctrl-Enter | Run the test with current code |
Ctrl-Shift-K | Reset the editor |
Ctrl-Shift-L | Clear console output |
Ctrl-Shift-X | Show the solution |
[ | Previous challenge |
] | Next challenge |
T | Back to top page |
? | Show this dialog |
ESC | Hide this dialog |
Shift-ESC | Blur focus from editor |