Ruby Ruby Basics Conditionals A Better "check_speed" Method

Stuck 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"

This 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".

2 Answers

Chanda Lupambo
Chanda Lupambo
Pro Student 23,538 Points

Your error is actually syntax, in Ruby it isn't else if, thats java. In ruby it is elsif :) hope that helped!

Jay McGavren
Jay McGavren
Treehouse Teacher

Also, 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