0
0
Kotlinprogramming~10 mins

When with multiple conditions in Kotlin - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A"Saturday", "Sunday"
B"Saturday", "Sunday", "Friday"
C"Saturday"
D"Sunday"
Attempts:
3 left
💡 Hint
Common Mistakes
Putting multiple values without commas
Using multiple when branches instead of one with multiple values
2fill in blank
medium

Complete 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'
A'x', 'y', 'z'
B'a', 'e', 'i'
C'a', 'b', 'c'
D'a', 'e', 'i', 'o', 'u'
Attempts:
3 left
💡 Hint
Common Mistakes
Using double quotes instead of single quotes for characters
Listing only some vowels
3fill in blank
hard

Fix 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'
A(1, 2, 3)
B1, 2, 3
C[1, 2, 3]
D"1, 2, 3"
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses or brackets around multiple values
Putting multiple values inside a string
4fill in blank
hard

Fill 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'
A"Saturday", "Sunday"
Belse
C"Monday", "Tuesday", "Wednesday", "Thursday", "Friday"
D"Holiday"
Attempts:
3 left
💡 Hint
Common Mistakes
Using else in the first branch
Listing all days explicitly instead of else
5fill in blank
hard

Fill 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'
A'a', 'e', 'i', 'o', 'u'
B'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
Celse
D'b', 'c', 'd'
Attempts:
3 left
💡 Hint
Common Mistakes
Using else in the middle branch
Not listing all digits
Using quotes incorrectly