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

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

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!