Challenge - 5 Problems
Swift Print 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 print statement?
Look at the code below. What will it print when run?
Swift
print("Hello, \"Swift\" world!")
Attempts:
2 left
💡 Hint
Remember how escape characters work in strings.
✗ Incorrect
The backslash \ is used to escape the double quotes inside the string, so they appear as part of the output.
❓ Predict Output
intermediate2:00remaining
What does this Swift code print?
Check the code and choose the correct output.
Swift
let name = "Anna" print("Hello, \(name)!")
Attempts:
2 left
💡 Hint
Look at how Swift uses \(variable) inside strings.
✗ Incorrect
Swift replaces \(name) with the value of the variable name, which is "Anna".
❓ Predict Output
advanced2:00remaining
What is the output of this Swift code with multiple print statements?
Analyze the code and select the correct output sequence.
Swift
print("Line 1") print("Line 2", terminator: " ") print("Line 3")
Attempts:
2 left
💡 Hint
Check how the terminator parameter changes the print behavior.
✗ Incorrect
The second print uses terminator: " " which means it ends with a space instead of a new line, so Line 3 prints on the same line after a space.
❓ Predict Output
advanced2:00remaining
What will this Swift code print?
Consider the code and pick the correct output.
Swift
let number = 5 print("Number is \(number * 2)")
Attempts:
2 left
💡 Hint
Swift evaluates expressions inside \( ) in strings.
✗ Incorrect
The expression number * 2 is calculated to 10 and printed inside the string.
❓ Predict Output
expert3:00remaining
What is the output of this Swift code using multiline string and print?
Look carefully at the code and select the exact output.
Swift
let poem = """ Roses are red, Violets are blue, Swift is fun, And so are you. """ print(poem)
Attempts:
2 left
💡 Hint
Multiline strings keep line breaks as they are.
✗ Incorrect
The multiline string preserves the line breaks and prints exactly as written.