0
0
Swiftprogramming~10 mins

Bool type and 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 declare a Boolean variable set to true.

Swift
let isSunny: Bool = [1]
Drag options to blanks, or click blank then click option'
Atrue
BTrue
C1
D"true"
Attempts:
3 left
💡 Hint
Common Mistakes
Using uppercase True instead of lowercase true
Using numbers like 1 instead of Boolean values
Using strings like "true" instead of Boolean literals
2fill in blank
medium

Complete the code to check if both conditions are true using a logical AND operator.

Swift
let canGoOutside = isSunny [1] hasFreeTime
Drag options to blanks, or click blank then click option'
A||
B==
C&&
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using OR operator (||) instead of AND
Using equality (==) instead of logical operators
Using inequality (!=) instead of logical operators
3fill in blank
hard

Fix the error in the code by choosing the correct logical NOT operator.

Swift
let isRaining = false
let shouldTakeUmbrella = [1]isRaining
Drag options to blanks, or click blank then click option'
A!
Bnot
C~
D!!
Attempts:
3 left
💡 Hint
Common Mistakes
Using ~ which is a bitwise NOT, not logical NOT
Using 'not' which is not valid Swift syntax
Using double exclamation marks (!!) which is invalid
4fill in blank
hard

Fill the blank to create a Boolean expression that is true if either it is weekend or you have no homework.

Swift
let canRelax = isWeekend [1] noHomework
Drag options to blanks, or click blank then click option'
A!=
B&&
C==
D||
Attempts:
3 left
💡 Hint
Common Mistakes
Using AND (&&) instead of OR
Using equality (==) or inequality (!=) operators incorrectly
5fill in blank
hard

Fill all three blanks to create a Boolean expression that is true if the word's length is greater than 3 and the word is not empty.

Swift
let word = "apple"
let condition = (word.count [1] 3) [2] (word [3] "")
Drag options to blanks, or click blank then click option'
A>
B&&
C!=
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using == instead of != to check for non-empty string
Using || instead of && which changes logic
Using < instead of > for length comparison