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
return 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
Cauli Tomaz12,362 Points
Ruby 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
def check_speed(car_speed) if (car_speed > 40) && (car_speed <= 50) 'safe' else 'unsafe' end end