Challenge - 5 Problems
Navigation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this React navigation component?
Consider this React component that renders navigation links. What will be displayed in the browser?
React
import React from 'react'; import { Link } from 'react-router-dom'; export default function Nav() { return ( <nav aria-label="Main navigation"> <ul> <li><Link to="/home">Home</Link></li> <li><Link to="/about">About</Link></li> <li><Link to="/contact">Contact</Link></li> </ul> </nav> ); }
Attempts:
2 left
💡 Hint
Remember that React Router's Link uses 'to' for navigation paths.
✗ Incorrect
The component uses React Router's Link with 'to' attributes correctly. It renders a nav with three clickable links labeled Home, About, and Contact.
❓ state_output
intermediate2:00remaining
What is the active link after clicking?
This React component highlights the active navigation link. After clicking the About link, what is the value of the active state?
React
import React, { useState } from 'react'; export default function Nav() { const [active, setActive] = useState('Home'); return ( <nav aria-label="Main navigation"> <ul> <li> <button onClick={() => setActive('Home')} aria-current={active === 'Home' ? 'page' : undefined}>Home</button> </li> <li> <button onClick={() => setActive('About')} aria-current={active === 'About' ? 'page' : undefined}>About</button> </li> <li> <button onClick={() => setActive('Contact')} aria-current={active === 'Contact' ? 'page' : undefined}>Contact</button> </li> </ul> </nav> ); }
Attempts:
2 left
💡 Hint
Clicking the About button triggers setActive with 'About'.
✗ Incorrect
The state 'active' starts as 'Home'. Clicking the About button calls setActive('About'), so active becomes 'About'.
📝 Syntax
advanced2:00remaining
Which option causes a syntax error in this React navigation code?
Identify which code snippet will cause a syntax error when used in a React component rendering navigation links.
React
function Nav() { return ( <nav> <ul> <li><a href="/home">Home</a></li> <li><a href="/about">About</a></li> <li><a href="/contact">Contact</a></li> </ul> </nav> ); }
Attempts:
2 left
💡 Hint
Check if all tags are properly closed.
✗ Incorrect
Option B is missing a closing tag after the first element, causing a syntax error in JSX.
🔧 Debug
advanced2:00remaining
Why does this navigation component not update the active link?
This React component tries to highlight the active link but fails. What is the reason?
React
import React, { useState } from 'react'; export default function Nav() { let active = 'Home'; return ( <nav aria-label="Main navigation"> <ul> <li> <button onClick={() => active = 'Home'} aria-current={active === 'Home' ? 'page' : undefined}>Home</button> </li> <li> <button onClick={() => active = 'About'} aria-current={active === 'About' ? 'page' : undefined}>About</button> </li> <li> <button onClick={() => active = 'Contact'} aria-current={active === 'Contact' ? 'page' : undefined}>Contact</button> </li> </ul> </nav> ); }
Attempts:
2 left
💡 Hint
React only re-renders when state or props change.
✗ Incorrect
The variable 'active' is a plain variable. Changing it does not trigger React to re-render the component, so the UI does not update.
🧠 Conceptual
expert2:00remaining
Which option best describes the purpose of 'aria-current' in navigation links?
In accessible navigation components, what is the main role of the 'aria-current' attribute on links?
Attempts:
2 left
💡 Hint
Think about screen readers and accessibility.
✗ Incorrect
'aria-current' is an accessibility attribute that tells screen readers which link is the current page, improving navigation clarity for users with disabilities.