Ruby Ruby Basics Conditionals A Better "check_speed" Method

Gregory James
Gregory James
4,437 Points

Speed check

I was able to get it to run in my RubyMine IDE but it isn't passing the challenge. Could anyone help me out?

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

2 Answers

Jay McGavren
STAFF
Jay McGavren
Treehouse Teacher

Here's a hint: what should check_speed(45) print? What about check_speed(60)?

Jay McGavren
STAFF
Jay McGavren
Treehouse Teacher

Also, you shouldn't have a condition after an else clause; I'm actually surprised that's not a syntax error. It should probably look like this:

  elsif speed > 60
    puts "too fast"
  end

Or better yet skip the check altogether, because we (should) already know from the prior clauses that the speed is greater than 60:

  else
    puts "too fast"
  end