I'm currently working on a simple app with nodejs and express. I load a random number, the user translates that number to spanish, and user submits it. I then need to compare the user's answer with the actual translation to see if the user was correct.
The route for my main page is pretty simple: I render a layout with a random number for a user's given level in the game, along with a random noun (both are just functions that i've required from a separate file).
app.get('/', catchError(async (req, res) => {
res.render("layout", {
num: randNumForLevel(0),
noun: randNoun(),
});
}))
However, here's my challenge: when the user clicks "submit" I need to compare their answer with the actual spanish translation (in this case it's for the number "20"). However, the way I've currently structured the code, I generated the number and passed it directly into my view, which means I don't have access to it in the next request/response cycle.
So my question is this: where should I store this randomly generated number (in this case "20") so that I still have access to it when the user submits the form. Should I put it in the session? app.locals? somewhere else? Not sure what best practice is, so would love some advice.
