"CSS Layout Basics" was retired on July 12, 2021. You are now viewing the recommended replacement.

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 trial

JavaScript Express Basics Parameters, Query Strings, and Modularizing Routes Linking Around the Application

A solution to handle invalid query string key 'side' value

if ( !side || ( side !== 'answer' && side !== 'question')) {
    res.redirect(`/cards/${id}?side=question`)
  }

2 Answers

This 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.

  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`);
  }