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 trialLyric Abbott
35,595 Pointshelp
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.
4 Answers
Aurelien Schlumberger
6,127 PointsThe trick is to check the equality between the number for car_speed and speed_limit using a second conditional statement with elsif
car_speed = 55
speed_limit = 55
if car_speed < speed_limit
too_fast = false
elsif car_speed == speed_limit
going_speed_limit = true
else
too_fast = true
end
Jeremy Lindstrom
6,646 PointsMy issue was I was typing elseif not elsif.
Joseph Groark
24,499 PointsI also put the elsif after the else and it didn't work?? Anyone know why that wouldn't work?
Javier Pacheco
3,418 PointsSo elsif must come before else. I think that is correct.
Elle Kasser
4,605 PointsElle Kasser
4,605 PointsI tried adding elsif after the else statement - that didn't work - I'm curious why?
Samuel Stephen
8,493 PointsSamuel Stephen
8,493 PointsI also added the elsif after the else and didn't understand why.
I'm not 100% sure, but I think the program would end when it finds out that if car_speed is more than (or equal to, in this case) speed_limit, it returns true for too_fast. Anything other than being equal or less means too_fast is true.
The else statement has won and so there is no need to go to elsif if it has decided that.
The reason for putting elsif first would be to check if the two variables are equal to each other before deciding it is too fast.