0
0
Kotlinprogramming~10 mins

Boolean type and logical operators 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 declare a Boolean variable named isSunny and assign it the value true.

Kotlin
val isSunny: Boolean = [1]
Drag options to blanks, or click blank then click option'
A"true"
B1
CTrue
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around true, which makes it a String instead of Boolean.
Using uppercase True, which is not valid in Kotlin.
2fill in blank
medium

Complete the code to check if isRaining is false using the logical NOT operator.

Kotlin
if ([1]isRaining) {
    println("No rain today!")
}
Drag options to blanks, or click blank then click option'
Anot
B~
C!
D!!
Attempts:
3 left
💡 Hint
Common Mistakes
Using not keyword which is not valid syntax in Kotlin.
Using ~ which is a bitwise operator, not logical NOT.
3fill in blank
hard

Fix the error in the code to correctly combine two Boolean conditions with the AND operator.

Kotlin
if (isWeekend [1] isHoliday) {
    println("Day off!")
}
Drag options to blanks, or click blank then click option'
A&&
Band
C||
D&
Attempts:
3 left
💡 Hint
Common Mistakes
Using and keyword which is not a valid operator in Kotlin.
Using single & which is bitwise AND, not logical AND.
4fill in blank
hard

Fill both blanks to create a Boolean expression that is true if isCold is true or isSnowing is true.

Kotlin
if (isCold [1] isSnowing) {
    println("Wear warm clothes!")
}
Drag options to blanks, or click blank then click option'
A&&
B||
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using && which requires both conditions to be true.
Using equality operators == or != which do not combine Boolean logic.
5fill in blank
hard

Fill all three blanks to create a Boolean expression that is true only if isWeekend is true, isHoliday is false, and hasPlans is false.

Kotlin
if (isWeekend [1] !isHoliday [2] !hasPlans) {
    println("Free day to relax!")
}
Drag options to blanks, or click blank then click option'
A&&
B||
Attempts:
3 left
💡 Hint
Common Mistakes
Using OR || which makes the condition true if any one is true.
Mixing AND and OR operators incorrectly.