Hello everyone,

I finished the CodeCademy’s JS course a while ago; I am trying to practice by solving challenges on codewars and came across this solution on calculating a number’s factorial:

```
function factorial(n) {
if (n < 0 || n > 12)
throw new RangeError();
return n <= 1 ? 1 : n * factorial(n - 1);
}
```

While I see what is happening at with the exception, I have a question on the second statement `return n <= 1 ? 1 : n * factorial(n - 1);`

. Is this a loop? And, how come it is using the function inside of itself?

I came up with the following:

```
function factorial(n)
{
//Return 1 when n is 0
if(n === 0){
return 1;
}
//Throw a RangeError exception when input is below 0 or above 12
else if (n < 0 || n > 12) {
throw 'RangeError'
}
//Calculate factorial
else {
let arrFactorial = []
for (i = n; i >= 1; i--){
let num = i
arrFactorial.push(num)
}
return arrFactorial.reduce(function(a, b){
return a * b;
}, 1)
}
}
```

I hope someone can explain. Thanks!