Challenge - 5 Problems
Text Modifier Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What is the color of the text shown?
Consider this SwiftUI code snippet. What color will the text appear on screen?
iOS Swift
Text("Hello SwiftUI")
.foregroundColor(.red)
.background(Color.yellow)Attempts:
2 left
💡 Hint
The foregroundColor modifier changes the text color, background changes behind the text.
✗ Incorrect
The foregroundColor(.red) sets the text color to red. The background(Color.yellow) sets the background behind the text to yellow.
📝 Syntax
intermediate2:00remaining
Which code correctly makes the text bold and italic?
Choose the SwiftUI code that applies both bold and italic styles to the text.
Attempts:
2 left
💡 Hint
bold() and italic() are modifiers that can be chained in any order.
✗ Incorrect
Both bold() and italic() are valid modifiers and can be chained in any order. font(.bold) is invalid because font expects a Font value, not a weight.
❓ lifecycle
advanced2:00remaining
What happens if you apply multiple foregroundColor modifiers?
Given this code, what color will the text display?
iOS Swift
Text("Hello")
.foregroundColor(.blue)
.foregroundColor(.green)Attempts:
2 left
💡 Hint
Later modifiers override earlier ones.
✗ Incorrect
In SwiftUI, modifiers are applied in order. The last foregroundColor(.green) overrides the earlier blue color.
🔧 Debug
advanced2:00remaining
Why does this code cause a compile error?
Identify the error in this SwiftUI code snippet:
iOS Swift
Text("Welcome") .fontWeight("bold")
Attempts:
2 left
💡 Hint
Check the type of argument fontWeight expects.
✗ Incorrect
fontWeight modifier requires a Font.Weight enum value like .bold, not a string literal.
🧠 Conceptual
expert2:00remaining
How does the order of modifiers affect the final text appearance?
Given these two code snippets, which statement is true about their rendered text?
Attempts:
2 left
💡 Hint
Think about what area the background color covers relative to padding.
✗ Incorrect
In the first snippet, padding is applied first, then background covers the padded area. In the second, background covers only the text, then padding adds space outside it.