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

Logical Operators Challenge

I don't understand why my code isn't passing...thanks in advance for the help :)

def check_speed(car_speed) 
check_speed = gets.chomp.to_i  

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

4 Answers

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

1) remove the whole line that does gets.chomp - they are not asking for it

2) do comparisons on car_speed, not check_speed (parentheses are not needed)

3) add another end after the if statement

4) remove puts - they are asking you to return that string, not print it, so you can just write "safe" on this line

Mark Josephsen
Mark Josephsen
8,803 Points

You need to have the whole 'if' statement in parenthesis. Like this: if ((check_speed >= 40) && (check_speed <= 50))

Ken Johansson
Ken Johansson
20,953 Points

I believe you need two ends. One for the function and one for the if statement.

Thanks for the replies - with your help I got the test to pass!