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 trialgerald blady
9,052 PointsIf Statement and &&
def check_speed(car_speed)
if (car_speed > 39) && (car_speed <= 50)
return "safe"
end
2 Answers
Geoff Parsons
11,679 PointsLooks like you forgot to close the if statement.
gerald blady
9,052 PointsAh! thank you for the set of eyes as I was looking at the end, not thinking I needed two. Simple mistake. appreciate it.
Geoff Parsons
11,679 PointsNo worries! It's easy to overlook, especially since many languages allow you to not close if statements when only a single line is present. The "ruby way" to achieve this would be to put it all on one line:
def check_speed(car_speed)
return "safe" if (car_speed > 39) && (car_speed <= 50)
end
But sometimes that can be hard to read, so it's a judgement call.
gerald blady
9,052 Pointsgerald blady
9,052 Pointsyou caught me while updating.
Where are you referring to? as I see all ( ) are closed?
Geoff Parsons
11,679 PointsGeoff Parsons
11,679 PointsAll you need is an
end
after the line withreturn "safe"
.