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 trialZachary 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...