Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a simple Kotlin function that prints a greeting.
Android Kotlin
fun greet() {
println([1])
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the string
Trying to call print inside println
✗ Incorrect
The println function requires a string argument in quotes to print text. So, "Hello, Android!" is correct.
2fill in blank
mediumComplete the code to declare a Kotlin variable that cannot be changed.
Android Kotlin
val language: String = [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes instead of double quotes
Not using quotes at all
✗ Incorrect
String values must be in double quotes in Kotlin. val means the variable is read-only.
3fill in blank
hardFix the error in the Kotlin function that returns the length of a string.
Android Kotlin
fun lengthOf(text: String): Int {
return text.[1]
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using length() with parentheses causes an error
Using size() which is not a String property
✗ Incorrect
In Kotlin, String length is a property accessed without parentheses: text.length
4fill in blank
hardFill both blanks to create a Kotlin list and print its size.
Android Kotlin
val fruits = listOf([1]) println(fruits.[2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using size() with parentheses causes error
Passing a single string instead of multiple elements
✗ Incorrect
listOf takes elements as arguments. size is a property to get the list length.
5fill in blank
hardFill all three blanks to create a Kotlin data class and instantiate it.
Android Kotlin
data class [1](val name: String, val age: Int) val person = [2]([3], 30)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Person() as class name
Not using quotes around the string argument
✗ Incorrect
Define data class Person, then create instance with Person("Alice", 30).