Complete the code to define a function with a default parameter value.
func greet(name: String = [1]) { print("Hello, \(name)!") } greet()
The default value for the parameter name is set to "Guest". Calling greet() without arguments prints "Hello, Guest!".
Complete the code to call the function with a custom argument.
func greet(name: String = "Guest") { print("Hello, \(name)!") } greet([1])
The function is called with the argument "Visitor" (a string in quotes). This prints "Hello, Visitor!".
Fix the error in the function definition by completing the default parameter value.
func multiply(number: Int = [1]) -> Int { return number * 2 } print(multiply())
The default value must be an integer (2), not a string or nil. This allows calling multiply() without arguments.
Fill both blanks to define a function with two parameters, one with a default value.
func describe(age: Int, city: String = [1]) { print("Age: \(age), City: \(city)") } describe(age: [2])
The parameter city has a default value "Unknown". The function is called with age: 30. The output is "Age: 30, City: Unknown".
Fill all three blanks to create a function with default parameters and call it with custom arguments.
func order(item: String = [1], quantity: Int = [2], price: Double = [3]) { print("Order: \(quantity) \(item)(s) at $\(price) each") } order(item: "Book", quantity: 3, price: 12.99)
The function order has default values: item = "Notebook", quantity = 1, price = 9.99. The call overrides all defaults with custom values.