Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to set the text color to red using modifier chaining.
iOS Swift
Text("Hello World")[1](.red)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using .background instead of .foregroundColor
Forgetting the dot before the modifier
Using .font instead of color modifier
✗ Incorrect
The .foregroundColor modifier changes the text color. Here, chaining it sets the text color to red.
2fill in blank
mediumComplete the code to add padding around the text using modifier chaining.
iOS Swift
Text("Welcome")[1]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using .frame instead of .padding
Forgetting parentheses after the modifier
Using .background instead of padding
✗ Incorrect
The .padding() modifier adds space around the view. Chaining it adds padding around the text.
3fill in blank
hardFix the error in the code by completing the modifier chain to make the text bold.
iOS Swift
Text("SwiftUI")[1]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using .italic instead of .bold
Forgetting parentheses after the modifier
Using .underline which only adds underline
✗ Incorrect
The .bold() modifier makes the text bold. Adding it correctly fixes the error.
4fill in blank
hardFill both blanks to chain modifiers that set the font size to title and the text color to blue.
iOS Swift
Text("Hello")[1](.title)[2](.blue)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using .background instead of .foregroundColor
Swapping the order of modifiers incorrectly
Using .padding instead of font or color
✗ Incorrect
The .font(.title) sets the font size to title style, and .foregroundColor(.blue) sets the text color to blue.
5fill in blank
hardFill all three blanks to chain modifiers that add padding, set the background color to yellow, and make the text italic.
iOS Swift
Text("Swift")[1]()[2](.yellow)[3]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using .bold instead of .italic
Forgetting parentheses after modifiers
Mixing order of modifiers
✗ Incorrect
The .padding() adds space around the text, .background(.yellow) sets the background color, and .italic() makes the text italic.