Bird
Raised Fist0
React Nativemobile~10 mins

Text component in React Native - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to display a simple text message in React Native.

React Native
import React from 'react';
import { View, [1] } from 'react-native';

export default function App() {
  return (
    <View>
      <[1]>Hello, world!</[1]>
    </View>
  );
}
Drag options to blanks, or click blank then click option'
AScrollView
BButton
CImage
DText
Attempts:
3 left
💡 Hint
Common Mistakes
Using View instead of Text to display text.
Using Button or Image which are for other purposes.
2fill in blank
medium

Complete the code to style the Text component with a font size of 20.

React Native
import React from 'react';
import { View, Text, StyleSheet } from 'react-native';

export default function App() {
  return (
    <View>
      <Text style=[1]>Styled Text</Text>
    </View>
  );
}

const styles = StyleSheet.create({
  bigText: {
    fontSize: 20,
  },
});
Drag options to blanks, or click blank then click option'
Astyles.bigText
BbigText
Cstyle.bigText
D{fontSize: 20}
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a plain object instead of the style reference.
Using incorrect variable names like 'style' or just 'bigText'.
3fill in blank
hard

Fix the error in the code by completing the Text component usage correctly.

React Native
import React from 'react';
import { View, Text } from 'react-native';

export default function App() {
  return (
    <View>
      <Text [1]>Incorrect usage</Text>
    </View>
  );
}
Drag options to blanks, or click blank then click option'
AfontSize=18
Bstyle={{fontSize: 18}}
Cstyle=fontSize:18
DfontSize={{18}}
Attempts:
3 left
💡 Hint
Common Mistakes
Passing style as a simple key-value pair without braces.
Using incorrect syntax like fontSize=18 directly.
4fill in blank
hard

Fill both blanks to create a Text component that is bold and blue.

React Native
import React from 'react';
import { View, Text, StyleSheet } from 'react-native';

export default function App() {
  return (
    <View>
      <Text style=[1]>[2]</Text>
    </View>
  );
}

const styles = StyleSheet.create({
  boldBlue: {
    fontWeight: 'bold',
    color: 'blue',
  },
});
Drag options to blanks, or click blank then click option'
Astyles.boldBlue
B'Bold Blue Text'
C'Hello World'
Dstyles.bold
Attempts:
3 left
💡 Hint
Common Mistakes
Using a style name that does not exist.
Passing non-string content inside Text.
5fill in blank
hard

Fill all three blanks to create a Text component with dynamic content and style.

React Native
import React from 'react';
import { View, Text, StyleSheet } from 'react-native';

export default function App() {
  const name = 'Alice';
  return (
    <View>
      <Text style=[1]>[2] {name}[3]</Text>
    </View>
  );
}

const styles = StyleSheet.create({
  greeting: {
    fontSize: 22,
    color: 'green',
  },
});
Drag options to blanks, or click blank then click option'
Astyles.greeting
B'Hello,'
C'!'
D'Hi'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to add punctuation or spaces.
Using incorrect style names.

Practice

(1/5)
1. What is the primary purpose of the Text component in React Native?
easy
A. To create buttons for user interaction
B. To handle navigation between screens
C. To display readable text on the screen
D. To load images from the internet

Solution

  1. Step 1: Understand the role of Text component

    The Text component is designed to show text content in the app UI.
  2. Step 2: Compare with other components

    Buttons handle clicks, navigation manages screens, images show pictures, so they are different.
  3. Final Answer:

    To display readable text on the screen -> Option C
  4. Quick Check:

    Text component = display text [OK]
Hint: Text component always shows text content [OK]
Common Mistakes:
  • Confusing Text with Button
  • Thinking Text handles navigation
  • Using Text for images
2. Which of the following is the correct way to apply a style to a Text component in React Native?
easy
A. Hello
B. Hello
C. Hello
D. Hello

Solution

  1. Step 1: Identify correct style prop syntax

    React Native uses style={{key: value}} with double curly braces for inline styles.
  2. Step 2: Check each option

    Hello uses correct syntax. Options A, B, C have wrong prop names or wrong value formats.
  3. Final Answer:

    <Text style={{fontSize: 20}}>Hello</Text> -> Option D
  4. Quick Check:

    Style prop = double curly braces object [OK]
Hint: Use style={{key: value}} for styling Text [OK]
Common Mistakes:
  • Using 'styles' instead of 'style'
  • Passing style as string
  • Using array without brackets
3. What will be displayed on the screen when this code runs?
const name = 'Anna';
return <Text>Hello, {name}!</Text>
medium
A. Hello, {name}!
B. Hello, Anna!
C. Hello, name!
D. Syntax Error

Solution

  1. Step 1: Understand JSX expression inside Text

    Curly braces inside Text allow embedding JavaScript variables.
  2. Step 2: Substitute variable value

    The variable name is 'Anna', so it replaces {name} with 'Anna'.
  3. Final Answer:

    Hello, Anna! -> Option B
  4. Quick Check:

    JSX variable inside Text = replaced value [OK]
Hint: Use curly braces to show variables inside Text [OK]
Common Mistakes:
  • Showing variable name as string
  • Forgetting curly braces
  • Syntax errors in JSX
4. Identify the error in this React Native code snippet:
return <Text style={{fontSize: 18, color: 'blue'}}>Welcome</Text>;
medium
A. No error, code is correct
B. Extra semicolon after Text component
C. Missing closing tag for Text
D. Incorrect style object syntax

Solution

  1. Step 1: Check JSX syntax

    The Text component is properly opened and closed with correct style prop syntax.
  2. Step 2: Verify semicolon usage

    Semicolon after JSX return is allowed in JavaScript; no syntax error.
  3. Final Answer:

    No error, code is correct -> Option A
  4. Quick Check:

    Valid JSX with style and semicolon [OK]
Hint: JSX can end with semicolon; style object must be valid [OK]
Common Mistakes:
  • Thinking semicolon breaks JSX
  • Missing closing tag
  • Wrong style syntax
5. You want to display a greeting that changes based on the time of day inside a Text component. Which code correctly shows "Good morning" if before noon, otherwise "Good afternoon"?
hard
A. {new Date().getHours() < 12 ? 'Good morning' : 'Good afternoon'}
B. new Date().getHours() < 12 ? 'Good morning' : 'Good afternoon'
C. {if (new Date().getHours() < 12) 'Good morning' else 'Good afternoon'}
D. {new Date().getHours() < 12 && 'Good morning'}

Solution

  1. Step 1: Use JavaScript expression inside Text

    Curly braces allow embedding JS expressions like ternary operator.
  2. Step 2: Check syntax correctness

    {new Date().getHours() < 12 ? 'Good morning' : 'Good afternoon'} uses correct ternary syntax. new Date().getHours() < 12 ? 'Good morning' : 'Good afternoon' misses braces, so shows text literally. {if (new Date().getHours() < 12) 'Good morning' else 'Good afternoon'} uses invalid if-else inside JSX. {new Date().getHours() < 12 && 'Good morning'} uses logical operators incorrectly and shows nothing in the afternoon.
  3. Final Answer:

    <Text>{new Date().getHours() < 12 ? 'Good morning' : 'Good afternoon'}</Text> -> Option A
  4. Quick Check:

    Ternary inside Text with braces = correct [OK]
Hint: Use ternary operator inside braces for conditional Text [OK]
Common Mistakes:
  • Missing braces for JS expression
  • Using if-else directly inside JSX
  • Using && and || incorrectly
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard