Welcome to the Treehouse Community
Looking to learn something new?
Dino Tudor1,767 Points
The And (&&) operator. Help solving quiz please.
What am i doing wrong? The first "if" statement doesn't set the correct value to return "safe" as asked. Please help me! Thanks!
def check_speed(car_speed) if (car_speed >= 40) && (car_speed <= 50) return safe elsif (car_speed <= 39) && (car_speed >= 51) return unsafe end end
unsafe are strings so you need to wrap them in quotes. In addition to that the conditions for your elseif is wrong. You are checking if
car_speed is less than or equal to 39 AND more than or equal to 51. A number can't be both less than 39 and greater than 51 at the same time, so that statement will never be true.
You don't actually need any conditions for the last statement though, it should run for any value that does not fit within the if conditions, so you can just use an
else statement like this:
def check_speed(car_speed) if (car_speed >= 40) && (car_speed <= 50) return "safe" else # else automatically runs if the above if statement does not run return "unsafe" end end