I am doing a Ruby exercise, but I can't figure out what is wrong. I need to modify the
suma
def suma(a, b)
"#{a} es mayor que #{b}" if a > b
"#{a} no es mayor que #{b}"
end
#test
p suma(10, 5) == "10 es mayor que 5"
p suma(4, 23) == "4 no es mayor que 23"
You're missing a
return in the first conditional.
def suma(a, b) return "#{a} es mayor que #{b}" if a > b "#{a} no es mayor que #{b}" end
Ruby by default will return the last statement in a method, but it allows for early returns. Since you want to return early if
a > b, you have to tell Ruby as much. Otherwise, it will execute the line and default to the last statement in the method for its return.