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

Taylor Porter
Taylor Porter
2,338 Points

The And (&&) Operator challenge help

I just don't understand what I'm doing wrong in this challenge here. Here's my error: SyntaxError: 8e514218-e8eb-49b8-b0da-ccbdd9bd5e89.rb:18: syntax error, unexpected end-of-input, expecting keyword_end but I don't understand what's wrong with my Syntax.

ruby.rb
def check_speed(car_speed)

  car_speed = gets.chomp.to_i

  if (car_speed >= 40) && (car_speed <= 50)
    return "Safe."

  elsif (car_speed > 50)
    return "Unsafe."

end

4 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey Taylor,

There are a few issues with the code. One syntax and a few that just don't comply with what the challenge is asking for (it can be very picky).

First, the syntax error: you are missing the end after the if statement

Second, you are using an elsif when it should be an else. You are only checking for one if condition, and if that is not met, then you move to an else not an elsif.

Now, for the Picky Challenge: 1. It wants you to return "safe" -> Lower Case and NO period. 2. It wants "unsafe" -> same thing (lower case and no period). 3. The challenge never asked you to code an input for car_speed, so that needs to be deleted.

With the exception of the one missing end, your code is correct, it just needs to be exactly what the challenge asks for, otherwise the code checker will fail and return "Bummer".

def check_speed(car_speed)

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

  else
    return "unsafe"

  end
end

Hope this helps. Keep Coding! :)

Harriet Ryder
Harriet Ryder
16,885 Points

You just need to put another 'end' at the bottom of your code! The if statement needs an 'end' and the def statement also needs to close with an 'end' :)

Taylor Porter
Taylor Porter
2,338 Points

Ohh, okay! So do I have to have a end after every single If, Else, Elsif?

Taylor Porter
Taylor Porter
2,338 Points

Oh wait I understand, I didn't have an end for the 'def'. Thanks so much for your help!