Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Ruby Ruby Operators and Control Structures Ruby Control Structures Else challenge

Update the check_speed method to compare the value in the car_speed parameter to the value in the speed_limit parameter.

Update the check_speed method to compare the value in the car_speed parameter to the value in the speed_limit parameter. If car_speed is greater than speed_limit, print the message "Slow down!" Otherwise, print the message "Safe travels!"

ruby.rb
def check_speed(car_speed, speed_limit)
  if(car_speed > speed_limit)
    print "Slow down!" 
  else
    print "Safe travels!"
end
check_speed(20, 40)

3 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,704 Points

Hey There,

If you look at the error message you get when you try and check your work, it gives away what's wrong.

syntax error, unexpected end-of-input, expecting keyword_end

So, your method and conditional is correct, except you forgot the end keyword to end the if statement. Add that in and you're good to go.

Keep coding! :dizzy:

thank you, Jason.

Hi. It took me a while too. Because in the previous videos training, we didn't need to end the if statement before starting the else statement. e.g:

print "Enter name: " name = gets.chomp

if name == "Jason" puts "That's my name, too!" else puts "Hi #{name}!" end

Nickolas Fuentes
Nickolas Fuentes
14,016 Points

Took me awhile to figure this out end is basically a ; like in Javascript!