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

How do I make the check_speed method produce the correct output here?

I don't understand why it's not producing the correct output..

ruby.rb
def check_speed(car_speed)
  # write your code here
  print "safe"
  if (car_speed >= 40) && (car_speed <= 50)
    puts "safe"
  end
end
Daniel Cunningham
Daniel Cunningham
21,109 Points

right now your code prints safe and then checks the car_speed variable. If the car speed is between 40-50 mph, it will then "puts 'safe'". What errors are you getting? What is the output supposed to be?

I'm supposed to "Set the return value of the "check_speed" method to the string "safe" depending on the following condition: The speed passed in as an argument is at least 40. The speed passed in as an argument is less than or equal to 50."

1 Answer

Daniel Cunningham
Daniel Cunningham
21,109 Points
  1. remove 'print "safe"' from the code.
  2. change 'puts' to 'return'

puts is not a return value. puts is great for having something printed to the screen for a user to read, but you need to 'return' it if you want ruby to be able to use it in another function.

great that worked! and makes a lot more sense.