Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to call the function with named arguments for clarity.
Kotlin
fun greet(name: String, age: Int) {
println("Hello, $name! You are $age years old.")
}
greet(name = "Alice", age = 30) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the function name or other unrelated words inside the string.
✗ Incorrect
Using the named argument 'name' inside the string prints the correct greeting.
2fill in blank
mediumComplete the function call using named arguments to improve readability.
Kotlin
fun calculateArea(length: Double, width: Double): Double {
return length * width
}
val area = calculateArea([1] = 5.0, [2] = 3.0) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong parameter name or omitting names.
✗ Incorrect
The first argument should be named 'length' and the second 'width' to match the function parameters.
3fill in blank
hardFix the error in the function call by using named arguments correctly.
Kotlin
fun displayInfo(name: String, city: String) {
println("$name lives in $city.")
}
displayInfo([1] = "Bob", city = "New York") Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Naming the wrong parameter or mixing named and positional arguments incorrectly.
✗ Incorrect
The first argument must be named 'name' to match the function parameter.
4fill in blank
hardFill both blanks to call the function with named arguments in any order.
Kotlin
fun orderCoffee(size: String, type: String) {
println("Order: $size $type coffee")
}
orderCoffee([1] = "Latte", [2] = "Large") Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using positional arguments or wrong parameter names.
✗ Incorrect
Named arguments allow any order; 'type' and 'size' must match parameters.
5fill in blank
hardFill all three blanks to define and call a function using named arguments for clarity.
Kotlin
fun [1](firstName: String, lastName: String, age: Int) { println("$firstName $lastName is $age years old.") } [1]([2] = "John", [3] = "Doe", age = 25)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong function or parameter names.
✗ Incorrect
The function name is 'printPerson'; arguments must match parameter names 'firstName' and 'lastName'.