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

jason limmm
jason limmm
7,903 Points

h2 text not appearing

my h2 text isn't appearing i don't know why

const express = require('express');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');

const app = express();

app.use(bodyParser.urlencoded({ extended: false}));
app.use(cookieParser());

app.set('view engine', 'pug');

const mainroute=require('./routes');
const cardroutes=require('./routes/card/cards')

app.use(mainroute);
app.use('/cards', cardroutes);

app.use((req, res, next) => {
  const err = new Error('Not Found');
  err.status = 404;
  next(err);
});

app.use((err, req, res, next) => {
  res.locals.error = err;
  res.status(err.status);
  res.render('error');
});

app.listen(3000, () => {
    console.log('The application is running on localhost:3000!')
});

card.js

const express = require('express');
const router = express.Router();
const data = require('../../data/flashcardData.json').data;
const cards = data.cards;

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

    const templateData = {text, hint};
    res.render('card', templateData);
});

module.exports = router;

card.pug

extends layout.pug

block content
  section#content
    h2= text
    if hint
      p
        i Hint: #{hint}