You're using the ternary operator incorrectly. You can't use return
.
You actually want this:
return number <= 0 ? 1 : number * factorial(number - 1);
Docs:
condition ? consequent : alternative
The condition expression must evaluate to true or false. If condition evaluates to true, the consequent expression is evaluated, and its result becomes the result of the operation. If condition evaluates to false, the alternative expression is evaluated, and its result becomes the result of the operation. Only consequent or alternative is evaluated.
This means that consequent
and alternative
should both evaluate to values that can be returned.