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 trialTom Lamb
9,472 PointsCan anyone tell me if my solution for showing hint when it is a question is ok or not great?
Basically i put the logic in the template and not in the actual route. Is that a problem?
// cards.js
const express = require('express');
const router = express.Router();
const { data } = require('../data/flashcardData.json')
const { cards } = data
router.get('/:id', (req, res) => {
const { side } = req.query;
const { id } = req.params;
const text = cards[id][side];
const { hint } = cards[id];
const templateData = { text, hint, side };
res.render("card", templateData);
});
module.exports = router;
// card.pug
extends layout.pug
block content
section#content
h2= text
if side === "question"
if hint
p
i Hint: #{hint}
1 Answer
Josh Seltzer
Full Stack JavaScript Techdegree Student 10,838 PointsIf it's any consolation, it's the same thing I did. Not sure if it's against any good practice rules, but it works fine.