0
0
Swiftprogramming~10 mins

Logical operators in Swift - Interactive Code Practice

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

Complete the code to check if both conditions are true.

Swift
let isSunny = true
let isWarm = true
if isSunny [1] isWarm {
    print("Let's go outside!")
}
Drag options to blanks, or click blank then click option'
A==
B||
C!
D&&
Attempts:
3 left
💡 Hint
Common Mistakes
Using || instead of && causes the condition to be true if either is true.
2fill in blank
medium

Complete the code to check if at least one condition is true.

Swift
let hasUmbrella = false
let isRaining = true
if hasUmbrella [1] isRaining {
    print("You can go outside.")
}
Drag options to blanks, or click blank then click option'
A||
B&&
C!=
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using && instead of || requires both conditions to be true.
3fill in blank
hard

Fix the error in the code to negate the condition correctly.

Swift
let isWeekend = false
if [1]isWeekend {
    print("Time to relax!")
}
Drag options to blanks, or click blank then click option'
A!
B&&
C||
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using == instead of ! does not negate the value.
4fill in blank
hard

Fill both blanks to check if the number is between 10 and 20 (inclusive).

Swift
let number = 15
if number [1] 10 [2] number <= 20 {
    print("Number is between 10 and 20.")
}
Drag options to blanks, or click blank then click option'
A>=
B<
C&&
D||
Attempts:
3 left
💡 Hint
Common Mistakes
Using || instead of && allows numbers outside the range.
5fill in blank
hard

Fill all three blanks to check if a character is a vowel (a, e, i, o, u).

Swift
let char: Character = 'e'
if char == 'a' [1] char == 'e' [2] char == 'i' [3] char == 'o' || char == 'u' {
    print("It's a vowel.")
}
Drag options to blanks, or click blank then click option'
A||
B&&
Attempts:
3 left
💡 Hint
Common Mistakes
Using && requires all conditions to be true, which is impossible here.