0
0
Kotlinprogramming~10 mins

Kotlin REPL and script mode - Interactive Code Practice

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

Complete the code to print "Hello, Kotlin!" in Kotlin REPL.

Kotlin
println([1])
Drag options to blanks, or click blank then click option'
AHello Kotlin
B"Hello, Kotlin!"
C'Hello, Kotlin!'
DHello, Kotlin!
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to use quotes around the string
Using single quotes which are for characters, not strings
2fill in blank
medium

Complete the Kotlin script to declare a variable with value 10.

Kotlin
val number: Int = [1]
Drag options to blanks, or click blank then click option'
Aten
B"10"
C10
D10.0
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes which makes the value a string
Using a decimal number for an Int type
3fill in blank
hard

Fix the error in the Kotlin script to print the sum of two numbers.

Kotlin
val sum = 5 [1] 3
println(sum)
Drag options to blanks, or click blank then click option'
A+
B-
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or multiplication instead of addition
Using division which changes the result
4fill in blank
hard

Fill both blanks to create a Kotlin map of words to their lengths.

Kotlin
val lengths = mapOf([1] to [2])
Drag options to blanks, or click blank then click option'
A"apple"
B5
C"banana"
D6
Attempts:
3 left
💡 Hint
Common Mistakes
Using numbers as keys without quotes
Mixing up keys and values
5fill in blank
hard

Fill all three blanks to create a Kotlin script that filters a list for numbers greater than 3.

Kotlin
val filtered = listOf(1, 2, 3, 4, 5).filter { it [1] [2] }
println(filtered[3])
Drag options to blanks, or click blank then click option'
A>
B3
C.joinToString()
D.toString()
Attempts:
3 left
💡 Hint
Common Mistakes
Using less than instead of greater than
Printing the list without formatting