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

I'm stuck on the "&&" logical operator question and cannot figure it out. I have tried a variety of ways. Help!

QUESTION: Set the return value of the "check_speed" method to the string "safe" depending on the following condition: The speed passed in as an argument is at least 40. The speed passed in as an argument is less than or equal to 50. You should use the "&&" logical operator to accomplish this task.

My current answer

def check_speed(car_speed) if (car_speed >= 40) && (car_speed <= 50) puts check_speed = "Safe" end

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

2 Answers

Hi Kelly,

Nice efforts, however, I found some minor mistakes and missing second "end" after if statements. "Safe" should be small letters which is "safe" according to the challenge and you need to use "return" instead puts.

Example:

def check_speed(car_speed)

  if (car_speed >= 40) && (car_speed <= 50)
    return "safe"
  end

end

Hope that helps.

Thank you so much! I know eventually it will become easier, but my brain really wasn't cooperating.

You are welcome, keep practice makes permanent wink. If that's satisfied your question, please make sure to assign best answer to help others' similar issues later.