Christopher Kemp3,446 Points
I can't get the program to return "speed OK" when there is an entry over 60. I thought I had the syntax correct in my else and elsif conditions, but the program still won't work
def check_speed(speed) if speed < 45 puts "too slow" elsif speed >= 45 && <= 60 puts "speed OK" else puts "too fast" end end
Jennifer NordellTreehouse Staff
Hi there! You're super close, but you do have a syntax error and it's in your
elsif statement. Every time you're doing an evaluation you have to say exactly what should be compared. You could have an evaluation that is dependent upon two different variables. Like if today is Friday and I have money, then go to the movies. In that case, you'd likely have a variable
elsif you wrote:
elsif speed >= 45 && <= 60
But that should be:
elsif speed >= 45 && speed <= 60
With each comparison, you have to explicitly say that speed is still what you're checking and not some other variable. Because it cannot work out which variable should be less than or equal to 60, it results in a syntax error.
Hope this helps!