Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a simple button with a label in React Native.
React Native
import React from 'react'; import { Button, View } from 'react-native'; export default function App() { return ( <View> <Button title=[1] onPress={() => alert('Clicked!')} /> </View> ); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the string
Using a variable name without defining it
✗ Incorrect
The title prop requires a string wrapped in quotes. Using single quotes like 'Click Me' is correct.
2fill in blank
mediumComplete the code to apply a background color style to the View component.
React Native
import React from 'react'; import { View, StyleSheet } from 'react-native'; export default function App() { return ( <View style={styles.container} /> ); } const styles = StyleSheet.create({ container: { backgroundColor: [1] } });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting quotes around the color code
Using a color name without quotes
✗ Incorrect
Colors in React Native styles must be strings, so '#3498db' is correct.
3fill in blank
hardFix the error in the code to correctly display a text label inside a View.
React Native
import React from 'react'; import { View, Text } from 'react-native'; export default function App() { return ( <View> <Text[1]>Hello, world!</Text> </View> ); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using single curly braces without an object
Using quotes instead of curly braces
✗ Incorrect
The style prop must be an object inside double curly braces, so style={{ fontSize: 20 }} is correct.
4fill in blank
hardFill both blanks to create a styled button with padding and a background color.
React Native
import React from 'react'; import { TouchableOpacity, Text, StyleSheet } from 'react-native'; export default function App() { return ( <TouchableOpacity style={{padding: [1], backgroundColor: [2]> <Text>Press me</Text> </TouchableOpacity> ); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '12px' instead of 12 for padding
Using color names without quotes
✗ Incorrect
Padding should be a number without units, and backgroundColor should be a string color code.
5fill in blank
hardFill all three blanks to create a responsive text input with placeholder and border color.
React Native
import React from 'react'; import { TextInput, StyleSheet } from 'react-native'; export default function App() { return ( <TextInput style={{ borderWidth: [1], borderColor: [2], padding: [3] }} placeholder="Enter text" /> ); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using strings for borderWidth or padding
Omitting quotes around borderColor
✗ Incorrect
Border width is a number (2), border color is a string color code, and padding is a number (10).