0
0
Kotlinprogramming~10 mins

Comparison operators in Kotlin - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A=
B==
C!=
D===
Attempts:
3 left
💡 Hint
Common Mistakes
Using single = which is assignment, not comparison.
2fill in blank
medium

Complete 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'
A>
B>=
C<=
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of >.
3fill in blank
hard

Fix 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'
A=
B==
C!=
D<>
Attempts:
3 left
💡 Hint
Common Mistakes
Using = which is assignment, or <> which is not valid in Kotlin.
4fill in blank
hard

Fill 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'
Aword
Bword.length
Cword.size
Dword.count()
Attempts:
3 left
💡 Hint
Common Mistakes
Using word.size or word.count() which are not properties of String in Kotlin.
5fill in blank
hard

Fill 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'
Akey
Bvalue
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of >, or mixing up key and value.