Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new map with values doubled.
Kotlin
val numbers = mapOf("a" to 1, "b" to 2, "c" to 3) val doubled = numbers.mapValues { it.value [1] 2 } println(doubled)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' adds 2 instead of doubling.
Using '-' or '/' changes values incorrectly.
✗ Incorrect
We use * to multiply each value by 2 to double it.
2fill in blank
mediumComplete the code to filter map entries with values greater than 2.
Kotlin
val numbers = mapOf("a" to 1, "b" to 3, "c" to 4) val filtered = numbers.filter { it.value [1] 2 } println(filtered)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' filters smaller values.
Using '==' filters only values equal to 2.
✗ Incorrect
We use '>' to keep entries with values greater than 2.
3fill in blank
hardFix the error in the code to convert map keys to uppercase.
Kotlin
val original = mapOf("one" to 1, "two" to 2) val upperKeys = original.mapKeys { it.key.[1]() } println(upperKeys)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'toUpperCase()' is deprecated in modern Kotlin.
Using 'toLowerCase()' changes to lowercase, not uppercase.
✗ Incorrect
In Kotlin 1.5+, 'uppercase()' is the correct function to convert strings to uppercase.
4fill in blank
hardFill both blanks to create a map of word lengths for words longer than 3 letters.
Kotlin
val words = listOf("cat", "house", "tree", "a") val lengths = words.filter { it.length [1] 3 }.associateWith { it.[2] } println(lengths)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' filters shorter words.
Using 'first' returns first character, not length.
✗ Incorrect
We filter words with length > 3 and map each word to its length.
5fill in blank
hardFill all three blanks to create a map with uppercase keys and values doubled for values > 1.
Kotlin
val data = mapOf("x" to 1, "y" to 2, "z" to 3) val result = data.filter { it.value [1] 1 }.mapKeys { it.key.[2]() }.mapValues { it.value [3] 2 } println(result)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' filters smaller values.
Using 'toUpperCase()' instead of 'uppercase()' in modern Kotlin.
✗ Incorrect
We filter values > 1, convert keys to uppercase, and double the values.