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 Elsif challenge

Not sure what I'm doing wrong

Challenge Task 1 of 1

Using an "elsif" statement, modify the code below to check whether or not the car_speed is equal to the speed_limit. If it is, set the variable "going_speed_limit" to true.

ruby.rb
car_speed = 55
speed_limit = 55

if car_speed < speed_limit
  too_fast = false
else
  too_fast = true
elsif
  going_speed_limit = true
end
end

6 Answers

Remember "elsif" requires a conditional statement. "else" also is the final statement. You also need only one "end" statement as the elsif is a part of the entire if conditional.

if car_speed < speed_limit
  too_fast = false
elsif car_speed == speed_limit
  going_speed_limit = true
else
  too_fast = true
end
Benjamin Miller
Benjamin Miller
4,344 Points

try this:

car_speed = 65 speed_limit = 60 too_fast = true

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

should complete the challenge.

Hope this helps!

David is right, the order is really important when writing these conditionals.

It's still not letting me pass the challenge

Will you put your code in here again?

I passed the challenge, this is my code if car_speed < speed_limit too_fast = false elsif car_speed = speed_limit going_speed_limit = true else too_fast = true end