0
0
Kotlinprogramming~10 mins

Val for immutable references in Kotlin - Interactive Code Practice

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

Complete the code to declare an immutable variable named name with the value "Alice".

Kotlin
val name: String = [1]
Drag options to blanks, or click blank then click option'
A"Alice"
BAlice
Cvar Alice
Dval Alice
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the quotes around the string value.
Using var instead of val.
2fill in blank
medium

Complete the code to declare an immutable integer variable age with the value 30.

Kotlin
val age: Int = [1]
Drag options to blanks, or click blank then click option'
A"30"
B30
Cage
Dval 30
Attempts:
3 left
💡 Hint
Common Mistakes
Putting quotes around numbers, making them strings.
Trying to declare the value with val again inside the assignment.
3fill in blank
hard

Fix the error in the code by completing the declaration of an immutable list of strings named colors.

Kotlin
val colors: List<String> = [1]
Drag options to blanks, or click blank then click option'
AmutableListOf("red", "green", "blue")
BarrayOf("red", "green", "blue")
ClistOf("red", "green", "blue")
D["red", "green", "blue"]
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets like in other languages.
Using mutableListOf() which is mutable, not immutable.
4fill in blank
hard

Fill both blanks to declare an immutable variable pi of type Double with the value 3.14.

Kotlin
val [1]: [2] = 3.14
Drag options to blanks, or click blank then click option'
Api
Bradius
CDouble
DInt
Attempts:
3 left
💡 Hint
Common Mistakes
Using Int type which cannot hold decimals.
Using a different variable name than pi.
5fill in blank
hard

Fill all three blanks to declare an immutable map named user with keys "name" and "age" and their respective values.

Kotlin
val [1] = mapOf([2] to "Bob", [3] to 25)
Drag options to blanks, or click blank then click option'
Auser
B"name"
C"age"
Dinfo
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the keys as strings.
Using wrong variable names.