Challenge - 5 Problems
Text Composable Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What is the output of this Text composable code?
Consider this Kotlin Compose code snippet:
What will the user see on the screen?
Text(text = "Hello, Compose!", color = Color.Red, fontSize = 20.sp)
What will the user see on the screen?
Android Kotlin
Text(text = "Hello, Compose!", color = Color.Red, fontSize = 20.sp)
Attempts:
2 left
💡 Hint
Remember that the color parameter controls text color and fontSize controls size.
✗ Incorrect
The Text composable shows the string with the specified color and font size. Color.Red sets the text color to red, and 20.sp sets the font size to 20 scale-independent pixels.
📝 Syntax
intermediate2:00remaining
Which option will cause a syntax error in this Text composable usage?
Look at these Text composable calls. Which one will cause a syntax error?
Attempts:
2 left
💡 Hint
Check if all parameters are properly referenced with their full names.
✗ Incorrect
FontWeight.Bold is an enum value and must be fully qualified. Using just Bold without FontWeight causes a syntax error because Bold is undefined.
❓ lifecycle
advanced2:00remaining
What happens if you update the text parameter of a Text composable dynamically?
Suppose you have a state variable holding a string and you pass it to Text composable's text parameter. What happens when you update that state?
Android Kotlin
var message by remember { mutableStateOf("Hello") }
Text(text = message)
// Later message = "Hi"Attempts:
2 left
💡 Hint
Think about how Compose handles state and recomposition.
✗ Incorrect
Compose tracks state changes and automatically recomposes UI elements that depend on that state, so the Text composable updates to show the new string.
advanced
2:00remaining
How to make a Text composable clickable to navigate to another screen?
You want to make a Text composable that when tapped navigates to a new screen. Which approach is correct?
Attempts:
2 left
💡 Hint
Modifiers can add click behavior to composables.
✗ Incorrect
Text composable itself has no onClick parameter, but you can add click behavior by applying Modifier.clickable and inside onClick call navigation functions.
🔧 Debug
expert2:00remaining
Why does this Text composable not show the expected color?
Given this code:
The text appears black instead of red. Why?
Text(text = "Hello", color = Color(255, 0, 0))
The text appears black instead of red. Why?
Android Kotlin
Text(text = "Hello", color = Color(255, 0, 0))
Attempts:
2 left
💡 Hint
Check the expected parameter types for Color constructor in Compose.
✗ Incorrect
In Compose, Color constructor takes float values between 0f and 1f for red, green, blue channels. Using integers 255 causes unexpected color (black).