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 trialChristopher Kemp
3,446 PointsCheck_speed
I can't get the program to return "speed OK" when there is an entry over 60. I thought I had the syntax correct in my else and elsif conditions, but the program still won't work
def check_speed(speed)
if speed < 45
puts "too slow"
elsif speed >= 45 && <= 60
puts "speed OK"
else
puts "too fast"
end
end
1 Answer
Jennifer Nordell
Treehouse TeacherHi there! You're super close, but you do have a syntax error and it's in your elsif
statement. Every time you're doing an evaluation you have to say exactly what should be compared. You could have an evaluation that is dependent upon two different variables. Like if today is Friday and I have money, then go to the movies. In that case, you'd likely have a variable day
and balance
.
In your elsif
you wrote:
elsif speed >= 45 && <= 60
But that should be:
elsif speed >= 45 && speed <= 60
With each comparison, you have to explicitly say that speed is still what you're checking and not some other variable. Because it cannot work out which variable should be less than or equal to 60, it results in a syntax error.
Hope this helps!