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 trialAndrew Ackerman
8,347 PointsHelp with elsif function
I'm not entirely sure what I'm doing wrong, I don't think I've quite got the hang of this elsif operator so any clarification and explanation would be appreciated!
car_speed = 55
speed_limit = 55
if car_speed < speed_limit
too_fast = false
else
too_fast = true
elsif == speed_limit = car_speed
going_speed_limit = true
end
2 Answers
Jennifer Nordell
Treehouse TeacherHi there! You're doing pretty well here, but there's some misunderstanding with the difference between comparison operators, assignment operators, and conditional statements. Let's take a look:
car_speed = 55
speed_limit = 55
if car_speed < speed_limit #if the car is going less than the speed limit
too_fast = false
elsif car_speed == speed_limit. #otherwise if the car is going the speed limit
going_speed_limit = true
else #if everything else is false...
too_fast = true
end
The else
should always be the last thing that happens. This says "if everything else fails do this". There are only three options here. The car is going less than the speed limit, the car is going the speed limit, or the car is speeding.
We use a single equals sign to assign a value to a variable. We use a double equals to ask if something is equal to something else. If you use a single equals, you aren't asking, you're telling it "you are now equivalent to this".
Hope this helps!
Andrew Ackerman
8,347 PointsThank you so much for that explanation! Much clearer now!