Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
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.✗ Incorrect
The keyword
var declares a mutable variable, and count is initialized to the integer 10.2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
== instead of = for assignment.Using arrow
-> or colon : which are not assignment operators.✗ Incorrect
The single equals sign
= is used to assign a new value to a variable.3fill in blank
hardFix 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'
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.✗ Incorrect
The keyword
var declares a mutable variable in Kotlin. val declares an immutable variable.4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
val instead of var for mutability.Using
Int type for a decimal number.✗ Incorrect
Use
var to declare a mutable variable and Double as the type for decimal numbers.5fill in blank
hardFill 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'
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.
✗ Incorrect
Use
var for a mutable variable, String as the type, and = to assign the value.