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 trialAvery Greenlees
4,615 PointsRuby Booleans Help! First if statement
I need some assistance putting up the framework for this challenge. I can fill in the blanks after that.
Thank you
car_speed = 50
speed_limit = 45
2 Answers
Steve Hunter
57,712 PointsHi Avery,
There are a couple of ways you can write this syntax. One would be all on one line, something like:
method_name if condition_met
The condition_met
could be a comparison such as something being greater than something else. Take the two variables in this challenge - car_speed
and speed_limit
. You could compare those with a binary operator, perhaps?
Alternatively, you can structure this over more than one line. Something like:
if condition_met
do_this
end
Let me know if you need more - those are just a couple of hints.
Steve.
Avery Greenlees
4,615 Pointssaves you space when you have a lot to look over
Avery Greenlees
4,615 PointsAvery Greenlees
4,615 PointsThanks! this did the trick. I ended up misplacing the else statement.
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsI think you need to use a multi-line
if
statement if you want an else clause.flash_car_speed if car_speed > speed_limit
... works fine for the single test. I don't think you can bung an
else
on the end of that so you'd need something like:Shame, 'cos I like the single line syntax better.