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

Carl Conroy
Carl Conroy
8,677 Points

Confident my code is correct but I get an error saying "Make sure you return 'safe' in the values range"

Where is the error in this code?

It looks right to me, but maybe a different pair of eyes can tell me where I made a mistake.

Thanks

ruby.rb
def check_speed(car_speed)
  # write your code here
  if car_speed >= 40 && car_speed <= 50
    puts "safe"
  else 
    puts "unsafe"
  end
end

2 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey Carl,

Your code is correct except for one thing: the challenge is asking you to return "safe" or "unsafe" and you are using puts. Just change puts to return and you'll be good to go.

Keep Coding! :)

Carl Conroy
Carl Conroy
8,677 Points

Thanks Jason.

What a nitpicky challenge. Strange it asks for "return" there when the entire video tutorial up to that point uses "puts".

Appreciate your response Jason, I was able to complete the challenge once I made that change.

Technically in the context of the question you could use either. The way it is formatted on the page is slightly misleading. It reads "The method below checks the speed of a car and returns a string value: either "safe" or "unsafe". Return "safe" if: The car_speed passed in as an argument is greater than or equal to the number 40. The car_speed passed in 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. :)"

where the words "string value", the variable names and the values you want to return are all formatted to denote explicit instruction. However "returns" and "return" are formatted the like the rest of the question where "return" could be formatted so it more explicitly says you MUST use the "return" over "puts" to complete the challenge.

This is just my suggestion as it was unclear to me but other people could experience this as well.

I agree with Carl. I was pretty confident that my code was correct when using put since the video discussed put. Super confusing.