Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Jeremy Biron
Courses Plus Student 4,135 PointsRuby Multiple Conditions - Stage 3 Challenge 1
I cannot figure out the answer to this question. Please help... :-)
Challenge Task 1 of 1
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. You should use the "&&" logical operator to accomplish this task.
def check_speed(car_speed)
if (car_speed > 40) && (car_speed <= 50)
return "safe"
else
return "unsafe"
end
end
check_speed(45)
4 Answers

Charles Smith
7,575 PointsSorry you don't need the parenthesis. The problem is that It must check if it's >=40
You also don't need to call the function.

Jeremy Biron
Courses Plus Student 4,135 PointsOk >= 40 solved the problem. I missed the part "at least" which should include 40. Thanks Charles!

Emilio Liriano
11,090 PointsSo you need to remove the first parentheses and make sure you close both the if statement and the define method. Here's how I solved it.
def check_speed(car_speed)
if car_speed >= 40 && car_speed <= 50
return "safe"
end
end

Charles Smith
7,575 PointsAlso what I did.

Charles Smith
7,575 PointsI think you need to wrap both conditions in parentheses.
if ( (car_speed > 40) && (car_speed <= 50) )

Jeremy Biron
Courses Plus Student 4,135 PointsThanks for the advice. Unfortunately it still isn't working. Here is another option I tried.
def check_speed(car_speed)
if ((car_speed > 40) && (car_speed <= 50))
return "safe"
end
end
check_speed = check_speed(45)
Jeremy Biron
Courses Plus Student 4,135 PointsJeremy Biron
Courses Plus Student 4,135 PointsForgot to include the "bummer" message.
Bummer! The check_speed method isn't producing the correct output.