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 trialBlake Baggett
Courses Plus Student 648 PointsStuck on Check Speed Method
I've coded my Check Speed method however i keep getting a syntax error on line 4. I'm sure this is what i should be doing but need some guidance :)
def check_speed(speed)
if speed < 45
puts "too slow"
else if speed >= 45 && <= 60
puts "speed OK"
else speed > 60
puts "too fast"
end
end
2 Answers
Chanda Lupambo
Courses Plus Student 27,336 PointsYour error is actually syntax, in Ruby it isn't else if, thats java. In ruby it is elsif :) hope that helped!
Jay McGavren
Treehouse TeacherAlso, you need a complete expression on both sides of the &&
operator. If we remove speed >= 45 &&
, here's what Ruby sees:
elsif <= 60
Less than or equal to what?? You need to specify that both comparison operations are using the speed
variable:
elsif speed >= 45 && speed <= 60
Blake Baggett
Courses Plus Student 648 PointsBlake Baggett
Courses Plus Student 648 PointsThis is what it should be doing
Update check_speed with this logic: If we pass a speed of less than 45, check_speed should print "too slow". If we pass a speed of 45 to 60, check_speed should print "speed OK". If we pass a speed of greater than 60, check_speed should print "too fast".