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

Seem to be struggling to come up with a solution for this problem, not actually sure what it's asking me to do!

can someone verify what the output should be, i's not very clear so I can't seem to be able to write code that passes the test.

Hi Alex,

What code have you tried so far?

3 Answers

Hi Jason,

This is what I've come up with, but the only return message is Bummer! Try again! I've tried so many variations and I can't get any to pass!

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

Thanks!

Try car_speed >= 40 for your 1st condition.

With your code, a speed of 39.3 could be passed in and it would return "safe" but that's not at least 40.

I'm not sure if the challenge is not being strict enough here but your original code does pass with the return on its own line.

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

this would be fine if only integer car speeds were passed in.

it's strange, I tried a lot of combinations and went through the threads already covering this topic and had trouble getting it to pass but eventually it did it!

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

got it to pass, changed it to >= 40, and put both conditions in parentheses, put the return on a new line too!

Thanks for the amazingly fast response guys!!