Bird
Raised Fist0
Swiftprogramming~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What is the purpose of an argument label in a Swift function?
easy
A. To store the return value of the function
B. To define the variable type inside the function
C. To clarify the meaning of each argument when calling the function
D. To create a new function inside another function

Solution

  1. Step 1: Understand argument labels

    Argument labels are used outside the function when calling it to make the call clearer.
  2. Step 2: Differentiate from parameter names

    Parameter names are used inside the function, but argument labels help the caller understand what each value means.
  3. Final Answer:

    To clarify the meaning of each argument when calling the function -> Option C
  4. Quick Check:

    Argument label = clarify call [OK]
Hint: Argument labels clarify calls, parameter names work inside [OK]
Common Mistakes:
  • Confusing argument labels with parameter names
  • Thinking argument labels define variable types
  • Assuming argument labels store return values
2. Which of the following is the correct way to declare a function with an argument label from and a parameter name start of type Int?
easy
A. func move(from: start Int) { }
B. func move(from start: Int) { }
C. func move(start from: Int) { }
D. func move(Int from start) { }

Solution

  1. Step 1: Recall Swift function syntax for labels

    The syntax is: func name(argumentLabel parameterName: Type) { }.
  2. Step 2: Match the syntax with given options

    func move(from start: Int) { } matches this syntax exactly: func move(from start: Int) { }.
  3. Final Answer:

    func move(from start: Int) { } -> Option B
  4. Quick Check:

    Argument label before parameter name [OK]
Hint: Argument label comes before parameter name in declaration [OK]
Common Mistakes:
  • Swapping argument label and parameter name order
  • Putting type before parameter name
  • Using invalid syntax with colons misplaced
3. What will be the output of the following Swift code?
func greet(person name: String) {
    print("Hello, \(name)!")
}
greet(person: "Anna")
medium
A. Hello, Anna!
B. Error: Missing argument label
C. Hello, name!
D. Hello, person!

Solution

  1. Step 1: Understand argument label and parameter name

    The function uses argument label person and parameter name name. The call uses person: "Anna".
  2. Step 2: Check the print statement

    Inside the function, name is used, so it prints "Hello, Anna!".
  3. Final Answer:

    Hello, Anna! -> Option A
  4. Quick Check:

    Argument label person calls parameter name name [OK]
Hint: Argument label used in call, parameter name used inside function [OK]
Common Mistakes:
  • Confusing argument label with parameter name in print
  • Calling function without argument label
  • Expecting argument label to print
4. Identify the error in this Swift function call:
func calculate(sum total: Int) {
    print(total)
}
calculate(5)
medium
A. Parameter name 'total' is incorrect
B. The print statement is invalid
C. Function should return a value
D. Missing argument label 'sum' in the function call

Solution

  1. Step 1: Check function declaration

    The function requires an argument label sum when called.
  2. Step 2: Check function call

    The call calculate(5) misses the argument label sum, so it causes an error.
  3. Final Answer:

    Missing argument label 'sum' in the function call -> Option D
  4. Quick Check:

    Argument label required in call [OK]
Hint: Always use argument labels in calls if declared [OK]
Common Mistakes:
  • Omitting argument labels in function calls
  • Confusing parameter names with argument labels
  • Expecting implicit argument labels
5. Given the function:
func update(user name: String, age years: Int) {
    print("User: \(name), Age: \(years)")
}

Which is the correct way to call this function to print User: John, Age: 30?
hard
A. update(user: "John", age: 30)
B. update(name: "John", years: 30)
C. update(user name: "John", age years: 30)
D. update("John", 30)

Solution

  1. Step 1: Identify argument labels and parameter names

    The function has argument labels user and age, with parameter names name and years.
  2. Step 2: Match call syntax

    The call must use argument labels: update(user: "John", age: 30) is correct.
  3. Final Answer:

    update(user: "John", age: 30) -> Option A
  4. Quick Check:

    Call uses argument labels, function uses parameter names inside [OK]
Hint: Use argument labels in call, parameter names inside function [OK]
Common Mistakes:
  • Using parameter names instead of argument labels in call
  • Trying to call with both labels and names together
  • Omitting argument labels entirely
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard