Ruby Ruby Basics Conditionals "if" Statements

patricia Re
patricia Re
652 Points

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,340 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

Troy Gooden
Troy Gooden
4,340 Points

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