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 trialAriel Espinal
5,451 PointsSyntax error on line 15 when i don't even have a line 15? Ruby
I seems to be missing something in my code, can't seem to wrap my head around it...
Question was:
The method below checks the speed of a car and returns a string value: either "safe" or "unsafe". Return "safe" if: The car_speed passed in as an argument is greater than or equal to the number 40. The car_speed passed in 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. :)
My Code:
def check_speed(car_speed)
if (car_speed >= 40) && (car_speed <= 50)
puts "safe"
else
puts "unsafe"
end
3 Answers
Rafael Capati
10,725 PointsHi Ariel, you have to close the function check_speed with a end keyword. The last end in your code is closing the if statement, but there is one missing for the function.
def check_speed(car_speed)
if (car_speed >= 40) && (car_speed <= 50)
puts "safe"
else
puts "unsafe"
end
end # <-- Missing end
Coleman Kelly
889 PointsI'm actually having an issue with this challenge as well. It keeps telling me I need to make I return safe. Here's my code:
def check_speed(car_speed)
if (car_speed >= 40) && (car_speed <= 50)
puts "safe"
else
puts "unsafe"
end
end
Ariel Espinal
5,451 PointsYea i'm receiving a communications error now trying to submit it. :(
Rafael Capati
10,725 PointsI see, you have to return the value back to the call function, for that you have to use the return keyword instead of the puts method.
def check_speed(car_speed)
if (car_speed >= 40) && (car_speed <= 50)
return "safe" # return the value
else
return "unsafe" # return the value
end
end
Coleman Kelly
889 PointsAh, that worked. I remember Jason talking about if/else/elsif and case/when but I don't remember return being mentioned in any of the videos prior to that challenge. Thanks for the help!
Ariel Espinal
5,451 PointsAriel Espinal
5,451 PointsAh! Good eye! However, i'm trying to submit my answer but I'm receiving a communications error. I could only assume the server is expecting another way to write it.