Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to render the message only if showMessage is true.
React
function Greeting({ showMessage }) {
return (
<div>
{showMessage && [1]
</div>
);
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to wrap the message in JSX tags.
Using a string without JSX tags.
✗ Incorrect
The expression uses logical AND to render the
Hello, world!
only if showMessage is true.2fill in blank
mediumComplete the code to render Loading... if isLoading is true, otherwise render Data loaded.
React
function Loader({ isLoading }) {
return (
<div>
{isLoading ? [1] : <p>Data loaded</p>}
</div>
);
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using plain strings without JSX tags.
Forgetting the colon ':' in the ternary operator.
✗ Incorrect
The ternary operator renders the JSX
Loading...
when isLoading is true.3fill in blank
hardFix the error in the code to correctly render Welcome back! only if isLoggedIn is true.
React
function Welcome({ isLoggedIn }) {
return (
<div>
{isLoggedIn && [1]
</div>
);
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using plain strings without JSX tags.
Trying to use invalid JSX syntax like .
✗ Incorrect
JSX requires elements to be wrapped in tags. Using
Welcome back!
is correct.4fill in blank
hardFill both blanks to render Admin Panel if isAdmin is true, otherwise render User Panel.
React
function Panel({ isAdmin }) {
return (
<div>
{isAdmin ? [1] : [2]
</div>
);
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the tags or texts for admin and user panels.
Using strings instead of JSX elements.
✗ Incorrect
The ternary operator chooses between
Admin Panel
andUser Panel
based on isAdmin.5fill in blank
hardFill all three blanks to render a greeting with the user's name if isLoggedIn is true, otherwise show a login button.
React
function UserGreeting({ isLoggedIn, userName }) {
return (
<div>
{isLoggedIn ? <p>Hello, [1]!</p> : <button [2]>[3]</button>}
</div>
);
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string 'userName' instead of the variable userName.
Forgetting the aria-label attribute on the button.
Using incorrect button text.
✗ Incorrect
The greeting uses the userName variable, the button has an aria-label for accessibility, and the button text is 'Log in'.