DEV Community

Cory Allen
Cory Allen

Posted on

Quick logic question... Express, Sequelize, & Handlebars

Having a tough time working out some logic. I don't know if it's because my brain is fried or what, but here is what I'm trying to do.

I have a table named "Questions", this table contains questions over an article. Fields are as follows: id, article_is, questions, answer1, answer2, answer3, answer4, correct_answer, explanations.

I would like to query 5 questions for the article and display them on the page obviously (this i can do). However, I am having "Writers block" persay with how to handle the form information with the Sequelize query. My query in my controller looks as follows:

exports.article_review = (req, res) => {
    Questions.findAll({
        limit: 5,
        where: {
            article_id: req.params.id
        },
        raw: true
    }).then(function(data) {

            res.render('article-review', {
                title: "Test your knowledge",
                questions: data,
                id: req.params.id
            })
    })
}
Enter fullscreen mode Exit fullscreen mode

For the life of me I cannot think of a way to appropriately process the form, compare each answer to each question to correct_answer, and display the results on the page. Any input would be great! Also, I'm sure the answer is simple, I've just been elbows deep in this project for 12+ hours a day for the last week.

Top comments (0)