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 trialNicole Fredette
1,353 PointsHow do I make the check_speed method produce the correct output here?
I don't understand why it's not producing the correct output..
def check_speed(car_speed)
# write your code here
print "safe"
if (car_speed >= 40) && (car_speed <= 50)
puts "safe"
end
end
Nicole Fredette
1,353 PointsI'm supposed to "Set the return value of the "check_speed" method to the string "safe" depending on the following condition: The speed passed in as an argument is at least 40. The speed passed in as an argument is less than or equal to 50."
1 Answer
Daniel Cunningham
21,109 Points- remove 'print "safe"' from the code.
- change 'puts' to 'return'
puts is not a return value. puts is great for having something printed to the screen for a user to read, but you need to 'return' it if you want ruby to be able to use it in another function.
Nicole Fredette
1,353 Pointsgreat that worked! and makes a lot more sense.
Daniel Cunningham
21,109 PointsDaniel Cunningham
21,109 Pointsright now your code prints safe and then checks the car_speed variable. If the car speed is between 40-50 mph, it will then "puts 'safe'". What errors are you getting? What is the output supposed to be?