0
0
Kotlinprogramming~10 mins

Var for mutable 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 a mutable variable named count initialized to 10.

Kotlin
var count: Int = [1]
Drag options to blanks, or click blank then click option'
Avar
Bval
C10
D"10"
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around 10, which makes it a string instead of an integer.
Using val instead of var for mutable variables.
2fill in blank
medium

Complete the code to change the value of the mutable variable score to 42.

Kotlin
score [1] 42
Drag options to blanks, or click blank then click option'
A->
B=
C==
D:
Attempts:
3 left
💡 Hint
Common Mistakes
Using == instead of = for assignment.
Using arrow -> or colon : which are not assignment operators.
3fill in blank
hard

Fix the error in the code by choosing the correct keyword to declare a mutable variable.

Kotlin
[1] name: String = "Alice"
Drag options to blanks, or click blank then click option'
Avar
Bconst
Cval
Dlet
Attempts:
3 left
💡 Hint
Common Mistakes
Using val when the variable needs to be mutable.
Using const or let which are not Kotlin keywords for variable declaration.
4fill in blank
hard

Fill both blanks to declare a mutable variable temperature of type Double initialized to 36.6.

Kotlin
[1] temperature: [2] = 36.6
Drag options to blanks, or click blank then click option'
Avar
Bval
CDouble
DInt
Attempts:
3 left
💡 Hint
Common Mistakes
Using val instead of var for mutability.
Using Int type for a decimal number.
5fill in blank
hard

Fill all three blanks to declare a mutable variable message of type String and assign it the value "Hello".

Kotlin
[1] message: [2] [3] "Hello"
Drag options to blanks, or click blank then click option'
Avar
BString
C=
Dval
Attempts:
3 left
💡 Hint
Common Mistakes
Using val instead of var for mutability.
Forgetting the assignment operator =.
Using wrong type or missing the type declaration.