Complete the code to define a method with a default parameter value.
def greet(name = [1]) puts "Hello, #{name}!" end
The default value for the parameter name should be a string, so it must be enclosed in quotes.
Complete the code to call the method with and without the default parameter.
def greet(name = "Guest") puts "Hello, #{name}!" end greet([1]) greet
When calling the method with a specific name, it must be a string with quotes.
Fix the error in the method definition with a default parameter.
def add_numbers(a, b = [1]) a + b end
The default value for b should be a number, so 0 is correct.
Fill both blanks to create a method with two parameters, one with a default value.
def order(item, quantity = [1]) puts "Order: #{quantity} #{item}(s)" end order("apple", [2])
The default quantity is 1, and the method call uses 5 as the quantity.
Fill all three blanks to define a method with default parameters and call it correctly.
def book_flight(destination = [1], seats = [2]) puts "Booking #{seats} seats to #{destination}." end book_flight([3])
The method defaults to "Paris" and 2 seats, but the call overrides the destination to "Tokyo".