Challenge - 5 Problems
Swift Semicolon Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Swift code with semicolons?
Consider this Swift code snippet where semicolons are used at the end of each statement. What will be printed when this code runs?
Swift
let a = 5; let b = 10; print(a + b);
Attempts:
2 left
💡 Hint
Semicolons separate statements but do not change how expressions are evaluated.
✗ Incorrect
Semicolons in Swift are optional and only separate statements. The code adds 5 and 10, printing 15.
❓ Predict Output
intermediate2:00remaining
What happens if you omit semicolons in Swift?
Look at this Swift code without semicolons. What will be the output?
Swift
let x = 3 let y = 7 print(x * y)
Attempts:
2 left
💡 Hint
Swift allows omitting semicolons if statements are on separate lines.
✗ Incorrect
Swift does not require semicolons if each statement is on its own line. The code multiplies 3 by 7 and prints 21.
❓ Predict Output
advanced2:00remaining
What is the output of this Swift code with multiple statements on one line?
This Swift code puts two statements on the same line separated by a semicolon. What will it print?
Swift
let name = "Swift"; print("Hello, \(name)!")
Attempts:
2 left
💡 Hint
Semicolons allow multiple statements on one line.
✗ Incorrect
The semicolon separates two statements on the same line. The print statement uses string interpolation to print Hello, Swift!
❓ Predict Output
advanced2:00remaining
What error does this Swift code produce without semicolons on the same line?
What error will this Swift code cause when run?
Swift
let a = 1 let b = 2 print(a + b)
Attempts:
2 left
💡 Hint
Swift requires semicolons to separate multiple statements on the same line.
✗ Incorrect
When two statements are on the same line without a semicolon, Swift raises a syntax error expecting a semicolon.
🧠 Conceptual
expert2:00remaining
How do semicolons affect Swift code readability and style?
Which statement best describes the role of semicolons in Swift code style and readability?
Attempts:
2 left
💡 Hint
Think about common Swift style guides and how code is usually written.
✗ Incorrect
Swift allows semicolons but style guides recommend omitting them to keep code clean and easy to read.