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 not sure where I'm going wrong in this question..

def check_speed(car_speed) if (car_speed >= 40) && (car_speed <= 50) return ("safe") elsif (car_speed <=40) && (car_speed >= 50) return ("unsafe") end

ruby.rb
def check_speed(car_speed)
 if (car_speed >= 40) && (car_speed <= 50)
   return ("safe")
 elsif (car_speed <=40) && (car_speed >= 50)
   return ("unsafe")
end

1 Answer

Tobias Helmrich
Tobias Helmrich
31,602 Points

Hey Sameet,

you have a few small mistakes in your code. Firstly you forgot to close your if block. The other problem is that the challenge doesn't want you to return "unsafe" in an elsif block so you should just return it in an else block. Also note that your elsif block would never be executed because there is no number that's less than or equal 40 and greater than or equal 50, if you would want to use the elsif block you should use the or (||) operator.

If you write it like this it should work

def check_speed(car_speed)
 if (car_speed >= 40) && (car_speed <= 50)
   return "safe"
 else
   return "unsafe"
 end
end

I hope that helps, if you don't understand something or have further questions feel free to ask, good luck! :)