29 lines
639 B
Ruby
29 lines
639 B
Ruby
|
def accelerate
|
||
|
puts "Stepping on the gas"
|
||
|
puts "Speeding up"
|
||
|
end
|
||
|
|
||
|
def sound_horn
|
||
|
puts "Pressing the horn button"
|
||
|
puts "Beep beep!"
|
||
|
end
|
||
|
|
||
|
def use_headlights(brightness)
|
||
|
puts "Turning on #{brightness} headlights"
|
||
|
puts "Watch out for deer!"
|
||
|
end
|
||
|
|
||
|
def use_headlights(brightness = "low-beam")
|
||
|
puts "Turning on #{brightness} headlights"
|
||
|
puts "Watch out for deer!"
|
||
|
end
|
||
|
|
||
|
def mileage(miles_driven, gas_used)
|
||
|
return miles_driven / gas_used
|
||
|
end
|
||
|
|
||
|
trip_mileage = mileage(400, 12)
|
||
|
puts "You got #{trip_mileage} MPG on this trip."
|
||
|
|
||
|
lifetime_mileage = mileage(11432, 366)
|
||
|
puts "This car averages #{lifetime_mileage} MPG."
|