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 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,860 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!