0
0
Swiftprogramming~20 mins

Argument labels and parameter names in Swift - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Swift Argument Labels Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of function call with argument labels
What is the output of this Swift code?
Swift
func greet(person name: String) {
    print("Hello, \(name)!")
}
greet(person: "Anna")
AHello, name!
BHello, person!
CError: Missing argument label
DHello, Anna!
Attempts:
2 left
💡 Hint
Check how the argument label and parameter name are used in the function call.
Predict Output
intermediate
2:00remaining
Result of function with omitted argument label
What will this Swift code print?
Swift
func multiply(_ a: Int, by b: Int) -> Int {
    return a * b
}
print(multiply(3, by: 4))
AError: Missing argument label for first parameter
B7
C12
DError: Missing argument label for second parameter
Attempts:
2 left
💡 Hint
The underscore (_) means the first argument label is omitted.
🔧 Debug
advanced
2:00remaining
Identify the error in function call with argument labels
Why does this Swift code cause an error?
Swift
func divide(_ numerator: Int, denominator: Int) -> Int {
    return numerator / denominator
}
divide(numerator: 10, denominator: 2)
AError: Unexpected argument label for first parameter
BError: Missing argument label for second parameter
CNo error, output is 5
DError: Cannot divide by zero
Attempts:
2 left
💡 Hint
Check the function definition and how the first parameter is called.
Predict Output
advanced
2:00remaining
Output of function with different argument labels and parameter names
What does this Swift code print?
Swift
func describe(person name: String, from city: String) {
    print("\(name) is from \(city).")
}
describe(person: "Liam", from: "Paris")
ALiam is from Paris.
Bperson is from city.
CError: Missing argument label
DLiam is from from.
Attempts:
2 left
💡 Hint
Look at how argument labels and parameter names are used in the function call.
🧠 Conceptual
expert
2:00remaining
Understanding argument labels and parameter names in Swift
Which statement about argument labels and parameter names in Swift is correct?
AParameter names are used only when calling the function.
BArgument labels appear in function calls, parameter names appear inside the function.
CArgument labels are used inside the function body to refer to parameters.
DYou cannot omit argument labels in Swift functions.
Attempts:
2 left
💡 Hint
Think about the difference between how you call a function and how you write its code.