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 Operators and Control Structures Ruby Control Structures Else challenge

Alphonse Cuccurullo
Alphonse Cuccurullo
2,513 Points

At a loss i need to make it true if the speed is greater then the speed limit an false if it is below.

What do i do?

ruby.rb
car_speed = 55
speed_limit = 60
too_fast= true

if car_speed > speed_limit
  puts too_fast
elsif
  car_speed < speed_limit
  puts !true
end

# Write your code here

1 Answer

You technically don't need the elsif because the only comparison that needs to be done is whether car_speed is greater than speed_limit. too_fast makes more sense to be defined within the scope of the conditional that way you don't need to override it although the way you are doing it is fine (and in some languages you'd need it defined first always).

I think your issues is that you just need to assign too_fast = false instead of puts !true.

if car_speed > speed_limit
  too_fast = true
else
  too_fast = false
end