Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print a greeting in Kotlin.
Kotlin
fun main() {
println([1])
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the quotes around the text.
Using print instead of println without parentheses.
✗ Incorrect
In Kotlin, println prints text to the screen. The text must be inside quotes.
2fill in blank
mediumComplete the code to declare a variable holding the number 10.
Kotlin
fun main() {
val number: Int = [1]
println(number)
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Putting the number inside quotes, making it a string.
Using a word instead of a number.
✗ Incorrect
In Kotlin, numbers are written without quotes. Quotes make them text.
3fill in blank
hardFix the error in the function declaration by completing the blank.
Kotlin
fun greet() : [1] { return "Hello" }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
Unit or void which mean no return value.Using
Int which is for numbers.✗ Incorrect
The function returns a text string, so its return type must be String.
4fill in blank
hardFill both blanks to create a list of numbers from 1 to 5.
Kotlin
fun main() {
val numbers = listOf([1], [2], 3, 4, 5)
println(numbers)
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around numbers, making them strings.
Using wrong numbers or text.
✗ Incorrect
The list holds numbers, so use numbers without quotes.
5fill in blank
hardFill all three blanks to create a function that adds two numbers and returns the result.
Kotlin
fun add([1]: Int, [2]: Int) : [3] { return a + b }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong parameter names that don't match the return statement.
Using
String as return type instead of Int.✗ Incorrect
The function parameters are two integers named a and b, and it returns an integer.