
Sean Paulson
5,047 PointsMy solution using pugjs
So I'm sure I'm ignorant but his solution seems a bit over engineered. Anyway check out line 12 of cards.js thats the main difference. let me know what you think. Would this break easy if a client told me to change something?
card.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];
//sets showside to the opposite of side.
let showside = side === "question" ? "answer" : "question";
const templateData = { text, hint, side, id , showside};
res.render('card', templateData);
});
module.exports = router;
card.pug
extends layout.pug
block content
section#content
h2= text
if side == "question"
p
i Hint: #{hint}
a(href=`http://localhost:3000/cards/${id}?side=${showside}`) #{side}