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

Alistair Mackay
Alistair Mackay
7,812 Points

Elsif Challenge: part 2

Another Newbie question: I'm stuck on this challenge. I understand the premise is to introduce an elsif section that introduces a branch that compares two variables: car_speed & speed_limit. and create a variable going_speed_limit = true.

The error I'm getting back is the following: "Bummer! SyntaxError: a8bbae90-cb75-4406-a935-4486c0671aca.rb:13: syntax error, unexpected keyword_elsif, expecting keyword_end elsif car_speed = speed_limit ^"

syntax suggests that I've missed out an instruction in the code that Ruby is not interpolating.

Any help with this would be greatly appreciated.

-PC

ruby.rb
car_speed = 55
speed_limit = 55

if car_speed < speed_limit
  too_fast = false
else
  too_fast = true
 elsif car_speed = speed_limit
  going_speed_limit = true
end
Alistair Mackay
Alistair Mackay
7,812 Points

Sorry! Still getting used to this site. As it turns out a fellow was stuck on the same problem about a month ago:

https://teamtreehouse.com/community/it-seems-there-is-an-error-i-am-typing-else-if-carspeed-speedlimit-and-it-is-not-accepting-the-addition

about to redo my exercise code to reflect the above link. I thin I see where I'm going wrong.

Alistair Mackay
Alistair Mackay
7,812 Points

Yeah! Fixed it now.

The basic error as I understand it was that I was placing my elsif branch out of order of the Syntax. As you can see from the above code elsif is below the the else on my copy which is why I think it was returning with a syntax error.

The correct/accepted method of the exercise I input the exact same code for the elsifโ€ข but this time is was before the *else section.

Rubber duckied the problem, chip if you any one can clarify the above explanation better.

Also how do you post corrections code to your posts?

1 Answer

Jacob Bergdahl
Jacob Bergdahl
29,119 Points

You can never put else before elif, because else responds if no conditions before it are true :)