Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print "Hello, Kotlin!" in Kotlin REPL.
Kotlin
println([1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to use quotes around the string
Using single quotes which are for characters, not strings
✗ Incorrect
In Kotlin, strings must be enclosed in double quotes. So to print a string, use println("string").
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes which makes the value a string
Using a decimal number for an Int type
✗ Incorrect
To assign an integer value to a variable, use the number without quotes. Quotes make it a string.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or multiplication instead of addition
Using division which changes the result
✗ Incorrect
The plus sign (+) adds two numbers in Kotlin.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using numbers as keys without quotes
Mixing up keys and values
✗ Incorrect
Use a string as the key and its length as the value in the map.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using less than instead of greater than
Printing the list without formatting
✗ Incorrect
The filter uses > 3 to select numbers greater than 3. The result is printed as a joined string.