Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to render the message only if show is true.
React
return ( <div> {show [1] <p>Hello!</p>} </div> );
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using || will render the right side even if the condition is false.
Using ? is for ternary expressions, not simple AND rendering.
✗ Incorrect
The logical AND operator (&&) renders the right side only if the left side is true.
2fill in blank
mediumComplete the code to render Loading... only when isLoading is true.
React
return ( <div> {isLoading [1] <span>Loading...</span>} </div> );
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using || will show the content even if isLoading is false.
Using ! negates the condition, which is not what we want here.
✗ Incorrect
Using && ensures Loading... shows only when isLoading is true.
3fill in blank
hardFix the error in the code to render Welcome back! only if isLoggedIn is true.
React
return ( <div> {isLoggedIn [1] <p>Welcome back!</p>} </div> );
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using || causes the message to always render.
Using | is a bitwise operator and causes errors.
✗ Incorrect
Logical AND (&&) correctly renders the message only when isLoggedIn is true.
4fill in blank
hardFill both blanks to render Admin Panel only if isAdmin is true and isLoggedIn is true.
React
return ( <div> {isAdmin [1] isLoggedIn [2] <h1>Admin Panel</h1>} </div> );
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using || would show the panel if either condition is true.
Using ? is for ternary expressions, not chaining conditions.
✗ Incorrect
Using && between both conditions ensures the panel shows only if both are true.
5fill in blank
hardFill all three blanks to render Special Offer only if isMember is true, hasCoupon is true, and isLoggedIn is true.
React
return ( <div> {isMember [1] hasCoupon [2] isLoggedIn [3] <div>Special Offer</div>} </div> );
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using || would show the offer if any condition is true.
Mixing operators causes unexpected rendering.
✗ Incorrect
All three conditions must be true, so use && between each condition.