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

Johnny Whitfield
Johnny Whitfield
14,024 Points

I don't know what's wrong with my code. Can you help me?

I have the two parameters and used the && operator. I defined safe as a string and am set to return it. Where am I going wrong?

ruby.rb
safe = "You are safe."


def check_speed(car_speed)
  if (car_speed >= 40) && (car_speed <= 50)
    return safe
  else
    return "You are not safe."
end

2 Answers

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

Set the return value of the "check_speed" method to the string "safe" depending on ...

  • you don't need an extra variable to store the String, your method can return it directly.
  • the return string should be "safe", not "You are safe.", grader is strict here.
  • for this challenge, you don't need to use else
def check_speed(car_speed)
  if (car_speed >= 40) && (car_speed <= 50)
    "safe"
  end
end