Challenge - 5 Problems
Route Parameters Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output when accessing /user/42?
Consider this Express route:
What will the server respond with when a client requests
app.get('/user/:id', (req, res) => { res.send(`User ID is ${req.params.id}`); });What will the server respond with when a client requests
/user/42?Express
app.get('/user/:id', (req, res) => { res.send(`User ID is ${req.params.id}`); });
Attempts:
2 left
💡 Hint
Look at how route parameters are accessed via req.params.
✗ Incorrect
The route parameter ':id' captures the part of the URL after '/user/'. It is accessible as req.params.id. So, requesting '/user/42' sets req.params.id to '42'.
📝 Syntax
intermediate2:00remaining
Which route definition correctly captures a product ID?
You want to define a route in Express that captures a product ID from the URL like
/product/123. Which of these route definitions is correct?Attempts:
2 left
💡 Hint
Route parameters start with a colon and match one segment.
✗ Incorrect
Option C correctly uses ':productId' to capture the product ID as a route parameter. Option C treats 'productId' as a literal path segment. Option C makes the parameter optional, which is not required here. Option C uses a wildcard which captures multiple segments, not just one.
🔧 Debug
advanced2:00remaining
Why does this route not capture the ID parameter?
Given this Express route:
What will happen when a client requests
app.get('/order/:id', (req, res) => { res.send(`Order ID: ${req.params.orderId}`); });What will happen when a client requests
/order/99?Express
app.get('/order/:id', (req, res) => { res.send(`Order ID: ${req.params.orderId}`); });
Attempts:
2 left
💡 Hint
Check the name used in the route parameter and the name used in req.params.
✗ Incorrect
The route defines the parameter as ':id', so req.params.id contains the value. But the code tries to access req.params.orderId, which is undefined. So the output shows 'Order ID: undefined'.
❓ state_output
advanced2:00remaining
What is the value of req.params after requesting /blog/2023/07?
Consider this Express route:
What JSON will the server send when a client requests
app.get('/blog/:year/:month', (req, res) => { res.json(req.params); });What JSON will the server send when a client requests
/blog/2023/07?Express
app.get('/blog/:year/:month', (req, res) => { res.json(req.params); });Attempts:
2 left
💡 Hint
Each colon-prefixed segment captures one part of the URL path.
✗ Incorrect
The route has two parameters: ':year' and ':month'. The URL '/blog/2023/07' matches both, so req.params contains both keys with their values.
🧠 Conceptual
expert3:00remaining
Which option correctly explains route parameter behavior with optional segments?
Given this route:
Which statement is true about accessing
app.get('/archive/:year/:month?', (req, res) => { res.send(req.params); });Which statement is true about accessing
/archive/2022 and /archive/2022/12?Attempts:
2 left
💡 Hint
The question mark after :month makes it optional.
✗ Incorrect
The question mark means the :month parameter is optional. When omitted, req.params does not include the month key at all. When present, it is included with its value.