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 trialkevinthecoder
10,791 PointsHaving trouble getting past Challenge Task 1 (use of &&)
OK, I'm having trouble getting past this first challenge. I am checking that the speed is indeed >= 40 AND is <= 50. I have tried several different ways and I can't get past this one. Code is posted below. Any suggestions??
def check_speed(car_speed)
if (check_speed >= 40) && (check_speed <= 50)
safe = check_speed
end
3 Answers
William Li
Courses Plus Student 26,868 PointsSet the return value of the "check_speed" method to the string "safe" depending on the following condition:
Some issues with your code
- missing a closing end for if conditional
- no return value
-
check_speed
is function name, you shouldn't use it on the function body here, use thecar_speed
argument instead.
def check_speed(car_speed)
# write your code here
if (car_speed >= 40) && (car_speed <= 50)
return "safe"
end
end
and the use of return keyword is optional here, but keeping the return keyword probably helps people see more clearly that "safe" is indeed the return value here.
Colin Marshall
32,861 PointsYou're close, here's the correct answer:
def check_speed(car_speed)
if (car_speed >= 40) && (car_speed <= 50)
return "safe"
end
end
You were using the method name where it should have been the method's argument car_speed
. You also need to return
a value and end
your if statement.
kevinthecoder
10,791 PointsOuch, I wasn't even close. I think that things are starting to get more challenging and that a person really has to 'think' more. I did indeed try the car_speed right off the bat immediately after the first FAIL and saw that immediately during my six or so attempts before posting to the forum. The return statement, however, completely threw me off (sigh). I believe the problem is that I'm not reading the statement/question in the quiz correctly (my fault); I am sometimes having problems interpreting what they are asking. Not sure how I'm going to resolve this going forward as I do tend to think daily in a different way than someone presents something to me (orally or written). This has always been a problem for me and I have never learned how to resolve it. Suggestions are welcome (if you have any!). Thanks so much.