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!
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

Andrew Carr
10,979 PointsWhy is my return value to "safe" for setting 'check_speed(car_speed)' not working?
Question is such: Set the return value of the "check_speed" method to the string "safe" depending on the following condition car_speed is greater than forty and less than fifty.
Code is such:
def check_speed(car_speed)
if car_speed >= 40 && car_speed <=50
puts "safe"
end
What am I not reading correctly? Thanks!
4 Answers
Christian McMullin
13,086 Pointsdef check_speed(car_speed)
if car_speed >= 40 && car_speed <= 50
return "safe"
end
end
instead of puts it needs to be return and that will fix the problem

ARNOLD SANDERS
5,266 Pointsyou are missing a second end.

Andrew Carr
10,979 PointsThat may have been part of it, but I wasn't setting the car_speed argument to "safe", which I think is sort of an odd thing to do instead of just outputting safe or not safe and leaving the argument as an integer.

ARNOLD SANDERS
5,266 PointsThe car speed argument is an integer . Its not a string called 'safe'. What you want to return is the string 'safe'. If you ran the method with a string instead of whats expected, it will give you a comparison error. Your code was correct as you wrote it, it was simply missing a second end. check out www.rep.it and see for yourself. Heres a small program to check the code:
def check_speed(car_speed)
if car_speed >= 40 && car_speed <=50
puts "safe"
end
end
print 'Enter a check_speed argument'
speed = gets.chomp
case speed
when '40'
'40'.to_i
check_speed(40)
when 'safe'
check_speed('safe')
else
exit
end