Bird
0
0

Identify the error in this Swift code snippet:

medium📝 Debug Q7 of 15
Swift - Operators and Expressions
Identify the error in this Swift code snippet:
let isAdult = age >= 18 ? true : false
let message = isAdult ? "Adult" "Minor"
AMissing colon between true and false in second ternary
BIncorrect use of quotes around true and false
CMissing colon between "Adult" and "Minor" in second ternary
DNo error, code is correct
Step-by-Step Solution
Solution:
  1. Step 1: Check second ternary operator syntax

    The second ternary operator is missing the colon between "Adult" and "Minor".
  2. Step 2: Confirm correct ternary syntax

    The correct syntax requires a colon separating the true and false values, so it should be: isAdult ? "Adult" : "Minor".
  3. Final Answer:

    Missing colon between "Adult" and "Minor" in second ternary -> Option C
  4. Quick Check:

    Ternary needs colon between true and false values [OK]
Quick Trick: Always put colon between true and false parts [OK]
Common Mistakes:
  • Omitting colon in ternary
  • Confusing quotes usage
  • Using comma instead of colon

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes