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 Adding Links

Why didn't this work?

I know this doesn't work but I don't understand why. It was what I was trying to do before checking out the solution

cards.js

router.get('/:id', (req, res) => {
  const { side } = req.query;
  const { id } = req.params;
  const text = cards[id][side];
  const { hint } = cards[id];
  let showHint = true;

  const templateData = { text, hint, showHint };
  if (side === 'question') {
    showHint = true;

  } else {
    showHint = false;
  }
  res.render('card', templateData);
});

module.exports = router; 

card.pug

extends layout.pug    

block content
  section#content
    h2= text
      if showHint = true
        p
          i Hint: #{hint}
Blake Larson
Blake Larson
13,014 Points

I rarely use pug but I would guess it is the if showHint = true line. I don't think that is checking a condition the way it is written, but rather assigning a value to showHint.

See if if showHint would work. That is the same as if showHint === true

Blake Larson Thanks, but that's what I thought but that didn't work either >.<

Blake Larson
Blake Larson
13,014 Points

What rendered for you? Did you log you variables before res.render() to see what was being sent? If hint, showHint and text are all what is expected it would have to be the pug file as long as there is no error in the terminal.

Blake Larson the conditional statement was working on the js file. But the for whatever reason the conditional on the pug wasn't running. Hope that makes sense.

1 Answer

James Crosslin
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
James Crosslin
Full Stack JavaScript Techdegree Graduate 16,882 Points

I know this is an old question, but I'm pretty sure the reason this didn't work was because in Javascript we use the loose (==) or strict (===) equality operators when checking a condition. You reassigned (=) showHint to true every time. You're also failing to update ahowHint on your server side because you're putting the value of showHint in your templateData object before you have your conditional statement. You should move the line where you assign template data down below the if else statement.

Also you nested your if statement within your h2. They should've been aligned vertically in your card.pug.