Challenge - 5 Problems
Props Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What will this React component render?
Consider this React component that uses props to display a greeting message. What will be the output when rendered with ?
React
function Greeting(props) { return <h1>Hello, {props.name}!</h1>; }
Attempts:
2 left
💡 Hint
Remember that props are accessed as properties of the props object inside JSX using curly braces.
✗ Incorrect
The component uses props.name inside curly braces to insert the value of the name prop. So it renders 'Hello, Alice!'. Other options either treat props as plain text or miss the value.
❓ state_output
intermediate2:00remaining
What is the output after clicking the button once?
This React component uses props and state. What will be the displayed text after clicking the button once?
React
import React, { useState } from 'react'; function Counter({ start }) { const [count, setCount] = useState(start); return ( <div> <p>Count: {count}</p> <button onClick={() => setCount(count + 1)}>Increment</button> </div> ); } // Rendered as <Counter start={5} />
Attempts:
2 left
💡 Hint
The initial state is set from the start prop. Clicking the button increases count by 1.
✗ Incorrect
The initial count is 5 from the start prop. Clicking the button once calls setCount(count + 1), so count becomes 6 and displays 'Count: 6'.
📝 Syntax
advanced2:00remaining
Which option correctly passes multiple props to a component?
You want to pass two props, title and subtitle, to a React component called Header. Which JSX syntax is correct?
Attempts:
2 left
💡 Hint
Props in JSX are passed like HTML attributes without commas and with quotes or curly braces.
✗ Incorrect
Option A correctly passes two props without commas and with quotes. Option A has a comma which is invalid syntax. Option A misses quotes around subtitle value. Option A is missing the closing slash or closing tag.
🔧 Debug
advanced2:00remaining
Why does this component fail to display the prop value?
This React component tries to display a prop but shows nothing. What is the cause?
React
function ShowMessage(props) { return <p>Message: props.text</p>; } // Rendered as <ShowMessage text="Hello!" />
Attempts:
2 left
💡 Hint
In JSX, dynamic values must be inside curly braces to be evaluated.
✗ Incorrect
JSX treats anything outside curly braces as plain text. So 'props.text' is shown literally, not the prop value. Wrapping it in curly braces fixes this.
🧠 Conceptual
expert2:00remaining
What happens if you modify props inside a React component?
Consider this code inside a React functional component:
props.name = "Changed";
What will happen when you try to modify props like this?
Attempts:
2 left
💡 Hint
Props are meant to be read-only inputs to components.
✗ Incorrect
Props are immutable in React. Trying to assign a new value to props properties causes an error or unexpected behavior. State or context should be used for mutable data.