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 trialHeather Stone
5,784 PointsSetting a conditional return value to a string, using &&
The objective for this code challenge is to set the return value of the method check_speed to the string "safe" when the two conditions are met (greater than 40 mph and less than or equal to 50 mph). In order to complete it we must also use the && operator. I've tried multiple permutations of the code you see below and got a variety of error messages, including "unexpected </>" and "Argument Error: 0 for 1". I'm totally unsure of what I'm doing wrong. Any help would be much appreciated. Thank you!
def check_speed(car_speed)
# write your code here
car_speed(>40) && (<=50)
puts "safe"
end
2 Answers
Salman Akram
Courses Plus Student 40,065 PointsHi Heather,
You could write if statement to solve this problem.
1 - The speed passed in as an argument is at least 40.
car_speed >= 40
2 - The speed passed in as an argument is less than or equal to 50.
car_speed <= 50
3 - Set the return value of the "check_speed" method to the string "safe"
return "safe" OR "safe" which will return automatically
def check_speed(car_speed)
# write your code here
if car_speed >= 40 && car_speed <= 50
"safe"
end
end
Hope that helps. ;)
Heather Stone
5,784 PointsThanks Salman! I'd tried if statements before but forgot the second "end". Added it and voila!