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 Randomize Cards

josephweiss2
josephweiss2
8,698 Points

Other solution

This is the solution i thought of How to make the "sideToShowDispaly" variable:

router.get('/:id', (req, res) => {
  const {side} = req.query;
  const {id} = req.params;
  const text = cards[id][side];
  const {hint} = cards[id];
  const cardToggle = req.query.side.toUpperCase();
  //const neww = Object.keys(cards[id])[2];

  const templateData = {text, id};

  if (side==='question') {
    templateData.sideToShow = 'answer';
    templateData.hint = hint;
  } else if (side === 'answer') {
    templateData.sideToShow = 'question';
  }

  templateData.sideToShowDispaly = templateData.sideToShow.charAt(0).toUpperCase() + templateData.sideToShow.slice(1);

  res.render('card', templateData);
});

1 Answer