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 Operators and Control Structures Logical Operators The And (&&) Operator

Robert Cornell
Robert Cornell
5,491 Points

Text Editor vs Challenge

Okay. I'm on this challenge and it is telling me the method is not returning the correct output.

When I pull my code out of the challenge window and put it in a text editor it does exactly what it is suppose to do (i.e. print the word "safe" if the vehicle speed is between 40 and 50)

It will not let me get past this challenge until I do precisely what it wants me to do. But given it is working in my text editor I am not certain what to do yet.

advice?

ruby.rb
def check_speed(car_speed)
  # write your code here
  if (car_speed == 40) && (car_speed <= 50)
    puts "safe"
  end
end

check_speed(40)

1 Answer

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

you only wrote one test case against your code, which is hardly suffice to ensure the code is working correctly, if I put in test case check_speed(41), it won't output safe.

There're couple issues here.

The speed passed in as an argument is at least 40.

It's asking for speed at least 40, meaning car_speed >= 40, not car_speed == 40.

Also, your method doesn't have any return value, because you use puts, you should use the return keyword instead.