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 trialJonathan Lepselter
1,864 PointsIssues setting a return value of a method as a string.
Im trying to set the return value of my method as the string "safe" in this code challenge. I've tried a few different ways but keep getting stuck. This is what I have so far:
def check_speed(car_speed)
if (car_speed ==40) && (car_speed <= 50)
puts "safe"
end
Im think my && operator is written correctly but Im getting stuck trying to set it as a string. Any suggestions?
2 Answers
Kenan Memis
47,314 PointsHi,
In Ruby puts command returns a nil value. So if you just want to return the "safe" string write your method without "puts" keyword.
Ruby automatically returns the last sentence of the method. So the following will be okey:
def check_speed(car_speed)
if (car_speed ==40) && (car_speed <= 50)
"safe"
end
end
Jason Anello
Courses Plus Student 94,610 PointsHi Jonathan,
You want to return the string rather than print it out.
Also the first part of your condition isn't correct. The car speed has to be at least 40. You have it equal to 40.
Should be car_speed >= 40
Jonathan Lepselter
1,864 PointsThanks Jason
Jonathan Lepselter
1,864 PointsJonathan Lepselter
1,864 PointsThanks Kenan