Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create an immutable list of integers.
Kotlin
val numbers = [1](1, 2, 3, 4, 5)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using mutableListOf instead of listOf creates a mutable list.
Using setOf creates a set, not a list.
✗ Incorrect
The listOf function creates an immutable list in Kotlin.
2fill in blank
mediumComplete the code to create a mutable list of strings.
Kotlin
val fruits = [1]("apple", "banana", "cherry")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using listOf creates an immutable list that cannot be changed.
Using arrayOf creates an array, not a list.
✗ Incorrect
The mutableListOf function creates a mutable list that can be changed later.
3fill in blank
hardFix the error in the code to create a mutable list of doubles.
Kotlin
val prices = [1](10.5, 20.0, 30.75)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using listOf creates an immutable list that cannot be changed.
Using setOf creates a set, not a list.
✗ Incorrect
To create a mutable list, use mutableListOf. listOf creates an immutable list.
4fill in blank
hardFill both blanks to create an immutable list and get its size.
Kotlin
val colors = [1]("red", "green", "blue") val size = colors.[2]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using mutableListOf instead of listOf for an immutable list.
Using count() instead of size property.
✗ Incorrect
listOf creates an immutable list, and size gets the number of items in the list.
5fill in blank
hardFill all three blanks to create a mutable list, add an item, and get the last element.
Kotlin
val animals = [1]("cat", "dog") animals.[2]("rabbit") val last = animals.[3]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using listOf instead of mutableListOf for a mutable list.
Using size instead of last() to get the last element.
✗ Incorrect
mutableListOf creates a mutable list, add adds an item, and last() gets the last element.