Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print "Weekend" when day is Saturday or Sunday.
Kotlin
val day = "Saturday" when(day) { [1] -> println("Weekend") else -> println("Weekday") }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Putting multiple values without commas
Using multiple when branches instead of one with multiple values
✗ Incorrect
In Kotlin, you can list multiple values separated by commas in a when branch to match any of them.
2fill in blank
mediumComplete the code to print "Vowel" when letter is 'a', 'e', 'i', 'o', or 'u'.
Kotlin
val letter = 'e' when(letter) { [1] -> println("Vowel") else -> println("Consonant") }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using double quotes instead of single quotes for characters
Listing only some vowels
✗ Incorrect
Multiple characters can be matched in one when branch by listing them separated by commas.
3fill in blank
hardFix the error in the when expression to match multiple numbers for "Small number".
Kotlin
val num = 3 when(num) { [1] -> println("Small number") else -> println("Other number") }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses or brackets around multiple values
Putting multiple values inside a string
✗ Incorrect
In Kotlin when branches, multiple values are listed separated by commas without parentheses or brackets.
4fill in blank
hardFill both blanks to print "Weekend" for Saturday or Sunday and "Weekday" otherwise.
Kotlin
val day = "Sunday" when(day) { [1] -> println("Weekend") [2] -> println("Weekday") }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using else in the first branch
Listing all days explicitly instead of else
✗ Incorrect
The first branch matches weekend days, the else branch covers all other days.
5fill in blank
hardFill all three blanks to print "Vowel", "Digit", or "Other" based on the input character.
Kotlin
val ch = '7' when(ch) { [1] -> println("Vowel") [2] -> println("Digit") [3] -> println("Other") }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using else in the middle branch
Not listing all digits
Using quotes incorrectly
✗ Incorrect
The when expression matches vowels, digits, and uses else for all other characters.