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 trial

Ruby Ruby Basics Conditionals A Better "check_speed" Method

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