Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create an immutable set with elements 1, 2, and 3.
Kotlin
val numbers = [1](1, 2, 3)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using mutableSetOf creates a mutable set, not immutable.
Using listOf creates a list, not a set.
✗ Incorrect
Use setOf to create an immutable set in Kotlin.
2fill in blank
mediumComplete the code to create a mutable set with elements "apple" and "banana".
Kotlin
val fruits = [1]("apple", "banana")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using setOf creates an immutable set that cannot be changed.
Using listOf creates a list, not a set.
✗ Incorrect
Use mutableSetOf to create a set that you can change later.
3fill in blank
hardFix the error in the code to create an immutable set of integers.
Kotlin
val nums = setOf[1]1, 2, 3)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets or curly braces instead of parentheses.
Missing the opening parenthesis.
✗ Incorrect
The setOf function requires parentheses around its arguments.
4fill in blank
hardFill both blanks to create a mutable set and add an element "orange".
Kotlin
val fruits = [1]("apple", "banana") fruits.[2]("orange")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using setOf creates an immutable set that cannot add elements.
Using remove instead of add to insert elements.
✗ Incorrect
Use mutableSetOf to create a mutable set and add to insert a new element.
5fill in blank
hardFill all three blanks to create an immutable set of numbers, check if it contains 5, and print the result.
Kotlin
val numbers = [1](1, 2, 3, 4, 5) val hasFive = numbers.[2](5) println([3])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using mutableSetOf instead of setOf for immutable set.
Printing the function call instead of the variable.
Using wrong method to check membership.
✗ Incorrect
Create an immutable set with setOf, check membership with contains, and print the boolean variable.