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

Syntax error "end of input"

I'm not sure why this snippet of code doesn't work. I keep getting the same error message and it basically says it expects the keyword end. I'm not sure what this means. Any thoughts? I've posted the instructions below for ease.

The method below checks the speed of a car and returns a string value: either "safe" or "unsafe". Return "safe" if: The car_speed passed in as an argument is greater than or equal to the number 40. The car_speed passed in as an argument is less than or equal to the number 50. Otherwise, return "unsafe". Hint: You should use the && logical operator to accomplish this task. :)

ruby.rb
def check_speed(car_speed)
  if (car_speed >= 40) && (car_speed <= 50)
    puts "safe"
  else
    puts "unsafe"
  end

2 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey Nathan,

You're really close. There are just two things:

  1. You didn't close out the method (there is a missing end).
  2. The challenge explicitly asks you to return the strings, but you are using puts.

Just fix up those two things and you're good to go.

Keep Coding! :) :dizzy:

Thanks! I didn't realize I needed two "end" statements. One to finish the if statement and another to finish the method. Also your "return" suggestion worked and I thought of that before my post but I was under the impression that "return" basically ended that line of code. Is that correct or have I misunderstood?

Thanks!

Jason Anders
Jason Anders
Treehouse Moderator 145,860 Points

Nathan Mahler

"Puts" stands for "Put String." So, essentially it's the same as "Print," but puts will add a new line and print will not.

"Return," on the other hand, just returns the value to the method, so nothing will actually be outputted to the screen. So, they are different commands, and the challenges are very strict on what they want.

:dizzy:

Thanks. I'm sure Beginners are always indebted to ppl who already know their stuff:).