Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Zachary Dunn
6,557 Pointsreturn was not covered in the previous video tutorial. how do i set the return value to equal a string?
how to set the return value
def check_speed(car_speed)
# write your code here
if (car_speed > 40) && (car_speed <= 50)
return 'safe'
end
1 Answer

Cauli Tomaz
12,362 PointsRuby doesn't require the "return" statement. It will always return the last variable of the function.
You can use it to force-exit from a function early though (http://stackoverflow.com/questions/4601498/what-is-the-point-of-return-in-ruby)
def check_speed(car_speed)
warning = 'unsafe'
if (car_speed > 40) && (car_speed <= 50)
warning = 'safe'
end
warning
end
or
def check_speed(car_speed)
if (car_speed > 40) && (car_speed <= 50)
'safe'
else
'unsafe'
end
end
Cauli Tomaz
12,362 PointsCauli Tomaz
12,362 PointsEdit: I forgot to add an 'end' to the if statement. This is also your case, and this might be causing your problem.
Zachary Dunn
6,557 PointsZachary Dunn
6,557 Pointsits still not working... hmmm
Cauli Tomaz
12,362 PointsCauli Tomaz
12,362 PointsThe problem is logic, not the ruby syntax.
I've read the problem and it states "The speed must be at least 40" and you are using (car_speed > 40)
This makes a speed of at least "41"!
Zachary Dunn
6,557 PointsZachary Dunn
6,557 Pointsnope. still not working
Cauli Tomaz
12,362 PointsCauli Tomaz
12,362 PointsCorrect answer, tested:
Zachary Dunn
6,557 PointsZachary Dunn
6,557 PointsThank You, Thank you...