use elsif instead

This commit is contained in:
Vitor Oliveira 2021-04-28 18:33:20 -07:00 committed by GitHub
parent d3d66e1ef1
commit 6e70556e39
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -9,12 +9,11 @@
def factorial(number)
if number < 0
"Please check your input number! The given number is a negative number."
else
if number == 0
elsif number == 0
"The factorial of #{number} is 1."
else
"The factorial of #{number} is #{(1..number).inject(:*)}."
end
result = (1..number).inject(:*)
"The factorial of #{number} is #{result}."
end
rescue
"Error: Please provide integer only!"