Ruby Ruby Basics Conditionals A Better "check_speed" Method

Bummer: We called check_speed with an argument greater than 60, but it didn't print "too fast".

I don't know what did I do wrong here? everything seems Ok but I don't get it why I get this Error? Bummer: We called check_speed with an argument greater than 60, but it didn't print "too fast".

program.rb
def check_speed(speed)
  if speed < 45
    puts "too slow"
  elsif speed >= 45
    puts "speed OK"
  else speed >= 60
    puts "too fast"
  end
end

1 Answer

joelearner
joelearner
36,513 Points

Hi pavilion,

The logic is a little confusing for this challenge. If you recall, the else statement comes into play when all of the if and elsif statements don't meet the criteria you set. So you can drop the >=60 on the else clause right away.

Then, you are left with adjusting the elsif clause. Since the if clause says <45, and you know that more than 60 will print "too fast", you just have to limit the speed for the "speed ok" condition. You can do this by saying speed <= 60.

Your finished code should look something like this:

def check_speed(speed)
  if speed < 45
    puts "too slow"
  elsif speed <= 60
    puts "speed OK"
  else
    puts "too fast"
  end
end

Cheers!