Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if a is equal to b.
Kotlin
val result = (a [1] b)
println(result) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using single = which is assignment, not comparison.
✗ Incorrect
In Kotlin, == checks if two values are equal.
2fill in blank
mediumComplete the code to check if x is greater than y.
Kotlin
if (x [1] y) { println("x is greater") }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of >.
✗ Incorrect
The > operator checks if the left value is greater than the right value.
3fill in blank
hardFix the error in the code to check if num is not equal to 10.
Kotlin
val check = (num [1] 10) println(check)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using = which is assignment, or <> which is not valid in Kotlin.
✗ Incorrect
The != operator checks if two values are not equal in Kotlin.
4fill in blank
hardFill both blanks to create a map of words to their lengths, but only for words longer than 3 characters.
Kotlin
val lengths = words.filter { word -> word.length > 3 }.associate { word -> [1] to [2] } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
word.size or word.count() which are not properties of String in Kotlin.✗ Incorrect
The key should be the word itself, and the value should be its length using word.length.
5fill in blank
hardFill all three blanks to filter a map to only include entries where the value is greater than 5.
Kotlin
val filtered = map.filter { ([1], [2]) -> [2] [3] 5 } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of >, or mixing up key and value.
✗ Incorrect
In the lambda, key and value represent the map entry. We check if value > 5.