Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Ruby Operators and Control Structures Logical Operators The And (&&) Operator

Sam Fitz
Sam Fitz
7,036 Points

How to make a Ruby method return a certain string based on its argument meeting certain criteria

I'm confused. The lesson before this code challenge showed how to use && and || inside If statements. I get that.

But the code challenge suddenly requires the use of this kind of statement inside a method, which I have a much looser grasp of than if statements.

Any help on this problem appreciated.

ruby.rb
def check_speed(car_speed)
  (car_speed > 40) && (car_speed <= 50)
  puts "safe"
end

2 Answers

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

The exercise wants you to "return value", not print (puts) it on the screen. Also, "at least 40" means that it can also be equal to 40, and the whole thing should be a part of the if statement - look at minute 2:30 in the video to see how this if statement should be constructed. Make some experiments and get back to me here if you still have problems.

Sam Fitz
Sam Fitz
7,036 Points

Hi Maciej,

Thank you so much for your response! By fooling around with the method a good bit more I finally achieved an acceptable response.

I have to say I had no idea an if statement could go inside a method. This was never demonstrated in any of the videos up to this point, nor did I notice an example of that in any of my Google searches about Ruby methods while trying to figure this one out.

But now I know. I appreciate you pointing me in the right direction!