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

Basto Biih
Basto Biih
5,334 Points

If Conditional Statement

Don't really know what else to do here, it ran with errors put I guess I'm close.

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

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey Basto,

You are on the right track and very close :thumbsup:
First, you'll need to put the print statements back to puts... challenges are very picky and don't like when you change the preloaded code that you weren't asked to change. :confused:

Next, there is just a logic error with the second if statement. The way you have it, the speed has to be exactly 45 and greater than or equal to 60 for it to return true, which is impossible. So, you'll need to adjust the first part to include anything greater than or equal to 45, and then change the second part to be less than or equal to 60.

Lastly, the instruction do not ask you to call the function. Doing this will cause the Code Checker to error out with a "Communication Error". Again, if the instructions don't say to do it... don't. So, just delete this line completely.

Once those are fixed up, the code will pass. Other than that, Great Job! :) :dizzy: