Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print a test message.
Kotlin
fun main() {
println([1])
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put quotes around the string.
Trying to print without using println.
✗ Incorrect
The println function prints the string inside quotes. We need quotes around the message.
2fill in blank
mediumComplete the code to check if a test result is true.
Kotlin
fun isTestSuccessful(result: Boolean): Boolean {
return result [1] true
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using single equals instead of double equals for comparison.
Using wrong comparison operators.
✗ Incorrect
Use == to compare values in Kotlin. A single = is for assignment.
3fill in blank
hardFix the error in the test function to return the correct message.
Kotlin
fun testMessage(passed: Boolean): String {
return if (passed) [1] else "Test failed"
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Returning a print statement instead of a string.
Forgetting quotes around the string.
✗ Incorrect
The function must return a string. So the true branch needs a string literal with quotes.
4fill in blank
hardFill both blanks to create a list of test results and check if all passed.
Kotlin
val results = listOf([1], [2], false) val allPassed = results.all { it } println(allPassed)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using numbers or strings instead of Booleans in the list.
Confusing
true and false values.✗ Incorrect
The list should contain Boolean values. Using true twice and false once creates a mixed result.
5fill in blank
hardFill all three blanks to create a map of test names to results and filter passed tests.
Kotlin
val testResults = mapOf([1] to [2], "test2" to false, "test3" to true) val passedTests = testResults.filter { it.value [3] true } println(passedTests.keys)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using strings instead of Booleans for test results.
Using wrong comparison operators in filter.
✗ Incorrect
The map needs a string key and a Boolean value. The filter checks if the value equals true.