Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to redirect the user to '/home'.
Express
app.get('/start', (req, res) => { res.[1]('/home'); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using res.send instead of res.redirect
Using res.render which is for templates
✗ Incorrect
The res.redirect() method sends a redirect response to the client, telling it to go to a different URL.
2fill in blank
mediumComplete the code to redirect with a 301 status code to '/new-page'.
Express
app.get('/old-page', (req, res) => { res.status(301).[1]('/new-page'); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using res.send instead of res.redirect
Not setting the status code before redirect
✗ Incorrect
Use res.redirect() after setting the status code to send a permanent redirect (301).
3fill in blank
hardFix the error in the code to properly redirect to '/dashboard'.
Express
app.get('/login', (req, res) => { res.redirect [1] '/dashboard'; });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting parentheses when calling res.redirect
Using square or curly brackets instead of parentheses
✗ Incorrect
The redirect method requires parentheses around the URL string.
4fill in blank
hardFill both blanks to redirect with a 302 status code to '/profile'.
Express
app.get('/user', (req, res) => { res.[1]([2], '/profile'); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using res.send instead of res.redirect
Using wrong status code like 301 for temporary redirect
✗ Incorrect
Use res.redirect(statusCode, url) to redirect with a specific status code like 302.
5fill in blank
hardFill all three blanks to redirect to '/logout' only if user is logged in.
Express
app.get('/exit', (req, res) => { if (req.user) { res.[1]([2], [3]); } else { res.send('Not logged in'); } });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using res.send instead of res.redirect
Forgetting quotes around the URL string
Using wrong status code
✗ Incorrect
Use res.redirect(302, '/logout') to redirect logged-in users to logout.