Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create an immutable map with two entries.
Kotlin
val colors = [1]("red" to "#FF0000", "green" to "#00FF00")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using mutableMapOf creates a mutable map, not immutable.
Using listOf or setOf creates collections, not maps.
✗ Incorrect
Use mapOf to create an immutable map in Kotlin.
2fill in blank
mediumComplete the code to create a mutable map and add a new entry.
Kotlin
val fruits = [1]("apple" to 1, "banana" to 2) fruits["orange"] = 3
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using mapOf creates an immutable map, so adding entries causes an error.
✗ Incorrect
mutableMapOf creates a map that can be changed after creation.
3fill in blank
hardFix the error in the code by choosing the correct function to create a mutable map.
Kotlin
val scores = [1]("Alice" to 10, "Bob" to 8) scores["Charlie"] = 7
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using mapOf causes an error when adding new entries.
✗ Incorrect
Only mutableMapOf allows adding new entries after creation.
4fill in blank
hardFill both blanks to create a map of squares for numbers greater than 3.
Kotlin
val squares = (1..5).filter { it [2] 3 }.associate { it to it [1] it }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using ** for power in Kotlin is incorrect.
Using < instead of > filters the wrong numbers.
✗ Incorrect
Use * for multiplication and > to filter numbers greater than 3.
5fill in blank
hardFill all three blanks to create a mutable map with uppercase keys and values greater than 0.
Kotlin
val result = data.entries.filter { (_, v) -> v [3] 0 }.associate { (k, v) -> [1] to [2] }.toMutableMap() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of > filters wrong entries.
Not transforming keys to uppercase.
✗ Incorrect
Use k.uppercase() for uppercase keys, keep values as v, and filter values greater than 0 with >.