Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a mutable list of strings named fruits.
Android Kotlin
val fruits = mutableListOf[1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets [] which is not valid syntax for list creation in Kotlin.
Using parentheses () without specifying the type.
✗ Incorrect
Use mutableListOf() to create an empty mutable list of strings in Kotlin.
2fill in blank
mediumComplete the code to add the string "Orange" to the fruits list.
Android Kotlin
fruits.[1]("Orange")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using append() which is not a Kotlin list method.
Using push() which is used in other languages like JavaScript.
✗ Incorrect
In Kotlin, use the add() method to add an element to a mutable list.
3fill in blank
hardFix the error in the code to create a map with keys as strings and values as integers.
Android Kotlin
val scores = mapOf<String, Int>[1]("Alice" to 10, "Bob" to 8)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets [] which causes syntax errors.
Using curly braces {} which are for lambda expressions.
✗ Incorrect
Use parentheses () to pass pairs to mapOf in Kotlin.
4fill in blank
hardFill both blanks to create a set of integers and add the number 5 to it.
Android Kotlin
val numbers = mutableSetOf[1](1, 2, 3) numbers.[2](5)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using append() which is not a Kotlin method for sets.
Omitting the type specification which can cause type inference issues.
✗ Incorrect
Use to specify the type and add() to add an element to a mutable set.
5fill in blank
hardFill all three blanks to create a map from strings to integers, add a new pair, and retrieve a value.
Android Kotlin
val ages = mutableMapOf[1]("John" to 25, "Jane" to 30) ages.[2]("Mike", 20) val age = ages[[3]]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using add() instead of put() to add to a map.
Using a variable instead of the string key when retrieving the value.
✗ Incorrect
Use to specify map types, put() to add a pair, and the key "Mike" to retrieve the value.