Hi All,
Two questions:
-
Is this the best forum to ask beginner questions? I’m learning Ruby
and I need a support community. -
I’m work on the factorial method on page 84 of Pine’s book. Here’s
the code:
def factorial num
if num < 0
return ‘You can’t take the factorial of a negative number!’
end
if num <= 1
1
else
num * factorial(num-1)
end
end
puts factorial(3)
My question is, why wouldn’t num go below 1 (like 0 or negative
integers) and result in a return of the string ‘You can’t take the…’?
Is something built into Ruby to stop at 0?
Thanks