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

How do I complete this challenge?

The method checks he speed of a car and returns a string value: eitherr "safe" or "unsafe" Return "safe" if: The car_speed is passed as an argument is greater than or equal to the number 40. The car_speed is passed as an argument is less than or equal to the number 50. Otherwise, return "unsafe". Hint: You should use the && logical operator to accomplish this task

ruby.rb
def check_speed(car_speed)


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

2 Answers

There's a couple issues. Most importantly you are missing an "end" for your check_speed method. Second, when you just say "unsafe" or "safe" without double quotes, Ruby looks for a variable called "safe" or "unsafe", and since there's no variable called "safe" or "unsafe", Ruby will return an error. Try putting double quotes around the "safe" and "unsafe" words to make them strings! :)

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

Good luck and tell me if there's any more errors!

Hope this helps, Alex

Also, the elsif needs to be changed to an else

Nice catch I forgot :)

Thanks for your detailed response!