Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialTrevor Maltbie
Full Stack JavaScript Techdegree Graduate 17,021 PointsA solution to handle invalid query string key 'side' value
if ( !side || ( side !== 'answer' && side !== 'question')) {
res.redirect(`/cards/${id}?side=question`)
}
2 Answers
Jelena Feliciano
Full Stack JavaScript Techdegree Student 12,729 PointsThis definitely works but it also seems like the !side
and the parentheses wrapped around the side !== 'answer' && side !== 'question'
are no longer needed and it looks much easier to read.
if ( side !== 'answer' && side !== 'question' ) {
res.redirect(`/cards/${id}?side=question`)
}
This was really helpful.
Tron Nguyen
10,847 Points if(side === 'question'){
templateData.hint = hint;
templateData.sideToShow = 'answer';
templateData.sideToShowDisplay = 'Answer';
}else if(side === 'answer'){
templateData.sideToShow = 'question';
templateData.sideToShowDisplay = 'Question';
}else{
return res.redirect(`/cards/${id}?side=question`);
}