Challenge - 5 Problems
Logical Operators Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of combined logical operators
What is the output of this Swift code snippet?
Swift
let a = true let b = false let c = true print(a && b || c)
Attempts:
2 left
💡 Hint
Remember that && has higher precedence than || in Swift.
✗ Incorrect
The expression a && b || c is evaluated as (a && b) || c. Since a && b is false, the result depends on c, which is true. So the final result is true.
❓ Predict Output
intermediate2:00remaining
Result of negation and OR operator
What does this Swift code print?
Swift
let x = false let y = true print(!x || y)
Attempts:
2 left
💡 Hint
Negation (!) flips the boolean value.
✗ Incorrect
!x is true because x is false. Then true || y is true. So the print outputs true.
❓ Predict Output
advanced2:00remaining
Output of complex logical expression
What is the output of this Swift code?
Swift
let p = false let q = true let r = false print((p || q) && !r)
Attempts:
2 left
💡 Hint
Evaluate inside parentheses first, then apply negation and AND.
✗ Incorrect
p || q is true because q is true. !r is true because r is false. So true && true is true.
❓ Predict Output
advanced2:00remaining
Value of variable after logical operations
What is the value of variable
result after running this Swift code?Swift
let a = true let b = false let c = true let result = !(a && b) && (b || c) print(result)
Attempts:
2 left
💡 Hint
Break down the expression step by step.
✗ Incorrect
a && b is false. Negation !(false) is true. b || c is true. So true && true is true.
❓ Predict Output
expert2:00remaining
Output of chained logical operators with precedence
What does this Swift code print?
Swift
let x = false let y = true let z = false print(x || y && !z || false)
Attempts:
2 left
💡 Hint
Remember that && has higher precedence than ||, and negation applies before &&.
✗ Incorrect
Evaluate !z first: true. Then y && true is true. So expression is x || true || false, which is true.