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 trialMarguerite Holden
6,075 PointsHow do I complete this challenge?
The method checks he speed of a car and returns a string value: eitherr "safe" or "unsafe" Return "safe" if: The car_speed is passed as an argument is greater than or equal to the number 40. The car_speed is passed as an argument is less than or equal to the number 50. Otherwise, return "unsafe". Hint: You should use the && logical operator to accomplish this task
def check_speed(car_speed)
if (car_speed >= 40) && (car_speed <= 50)
return safe
elsif
return unsafe
end
2 Answers
Alexander Davison
65,469 PointsThere's a couple issues. Most importantly you are missing an "end" for your check_speed method. Second, when you just say "unsafe" or "safe" without double quotes, Ruby looks for a variable called "safe" or "unsafe", and since there's no variable called "safe" or "unsafe", Ruby will return an error. Try putting double quotes around the "safe" and "unsafe" words to make them strings! :)
def check_speed(car_speed)
if (car_speed >= 40) && (car_speed <= 50)
return "safe"
elsif
return "unsafe"
end
end
Good luck and tell me if there's any more errors!
Hope this helps, Alex
Marguerite Holden
6,075 PointsThanks for your detailed response!
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsAlso, the
elsif
needs to be changed to anelse
Alexander Davison
65,469 PointsAlexander Davison
65,469 PointsNice catch I forgot :)