0
0
Kotlinprogramming~10 mins

How Kotlin compiles to JVM bytecode - Interactive Practice

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

Complete the code to declare a simple Kotlin function that returns a greeting.

Kotlin
fun greet() : String = [1]
Drag options to blanks, or click blank then click option'
Aprintln("Hello, JVM!")
B"Hello, JVM!"
CHello, JVM!
Dreturn "Hello, JVM!"
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the string
Using println instead of returning a string
2fill in blank
medium

Complete the code to create a Kotlin class with a primary constructor that takes a name.

Kotlin
class Person(val [1]: String)
Drag options to blanks, or click blank then click option'
Aname
Btitle
Cid
Dage
Attempts:
3 left
💡 Hint
Common Mistakes
Using unrelated parameter names like age or id
Forgetting to declare the parameter as val or var
3fill in blank
hard

Fix the error in the Kotlin function that prints a message.

Kotlin
fun printMessage() {
    println([1])
}
Drag options to blanks, or click blank then click option'
AHello JVM
Bprintln("Hello JVM")
C"Hello JVM"
Dreturn "Hello JVM"
Attempts:
3 left
💡 Hint
Common Mistakes
Passing unquoted text causing syntax errors
Using return inside println
4fill in blank
hard

Fill both blanks to create a Kotlin map comprehension that filters entries with values greater than 10.

Kotlin
val filtered = mapOf(1 to 5, 2 to 15, 3 to 20).filter { it.[1] [2] 10 }
Drag options to blanks, or click blank then click option'
Avalue
B>
C<
Dkey
Attempts:
3 left
💡 Hint
Common Mistakes
Using key instead of value
Using less than operator instead of greater than
5fill in blank
hard

Fill all three blanks to create a Kotlin map from a list of words with their lengths, filtering words longer than 3 letters.

Kotlin
val words = listOf("cat", "house", "dog", "elephant")
val lengths = words.associateWith { it.[1] }
val filtered = lengths.filter { it.key.[2] [3] 3 }
Drag options to blanks, or click blank then click option'
Alength
C>
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Using count which is a function, not a property
Using key incorrectly in associateWith