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 trial

Ruby Ruby Booleans Ruby Booleans Boolean Review

Ruby 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

boolean.rb
car_speed = 50
speed_limit = 45

2 Answers

Hi 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.

Thanks! this did the trick. I ended up misplacing the else statement.

I 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:

if car_speed > speed_limit
  flash_car_speed
else
  display_car_speed
end

Shame, 'cos I like the single line syntax better.

saves you space when you have a lot to look over