Is there any reason you've chosen to structure your answer like this? You could easily write it out as something like:
def report_back(value)
value < 100 && value > 50 ? message = 'number range: 50 - 100' : message = 'not'
puts message
end
number = gets.chomp.to_i
report_back(75)
You generally use case
when there are more than 3 options. Here, a simple if...else
would probably be a better choice, since there are really only 2 options. I chose to use a ternary operator here, but the ?..:
is identical to if...else
.
A few technical points
- there is no need for the
return
statements; Ruby has implicit return, so the return keyword isn't necessary.
- Using
puts
outside of the function to return data is generally discouraged; its best to use puts inside ie: in place of the return
keyword here
Hope that helps. You're off to a good start - you'll get it in no time!