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 Basics Conditionals "if" Statements

Define a method named check_speed that takes a single number representing a car's speed as a parameter. If the speed is

ef check_speed = "speed" if speed < 50 puts "Too fast" end if speed >55 puts "Too slow" end unless speed == 55 puts "speed ok" end end check_speed

program.rb
def check_speed = 100
        if check_speed > 55
    puts "Too fast"
    end
    if check_speed >55
    puts "Too slow"
        end
        if check_speed == 55
    puts "speed ok"
    end
end
Troy Gooden
Troy Gooden
4,352 Points

ok The way how you are writing your method to begin with might be wrong. And also you need to fix your comparison operators for "too fast" and "too slow". I wrote this up for you so you can compare:

def check_speed(speed)
    if speed > 55
    puts "Too fast"
    end
    if speed < 55
    puts "Too slow"
    end
    if speed == 55
    puts "speed ok"
    end
end

# check_speed(65)
# check_speed(45)
# check_speed(55)

Please note that i commented out the method call with arguments so you can see what each one produces when called. But when you do pass an argument it will produce the proper statement to be outputted. So for instance if we call the method "check_speed(65)" it will do the puts statement of "too fast" ....and if we do the "check_speed(45)" it will do the puts statement of "too slow", and finally if we do the call for "check_speed(55) " it will produce the "speed ok" I'm hoping this helped. please play around with it and let me know.

1 Answer

Thank you Troy

Troy Gooden
Troy Gooden
4,352 Points

Not a problem. Just doing my lil part in the community, let it be known many people have helped me.