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

Alec Jones
Alec Jones
5,510 Points

I do not understand when I get the error, Your code isn't returning the right output?

I already tried using return instead of puts.

ruby.rb
car_speed = 45

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

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,858 Points

Hey Alec,

First off, delete the car_speed = 45 line. The challenges don't like it when you add something it didn't ask for. Many times this will cause you to not be able to pass the challenge.

As to your code, everything is correct, except you did add another thing the challenge didn't want. The challenge just wants you to "Return" the value "safe," but you are trying to print it to the screen. Just use an implicit return at the end of the conditional.

def check_speed(car_speed)
  if (car_speed >= 40) && (car_speed <= 50)
  "safe"
  end 
end

Hope that helps you. Keep Coding! :)