DEV Community ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป

DEV Community ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป is a community of 963,673 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
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)

This post blew up on DEV in 2020:

js visualized

๐Ÿš€โš™๏ธ JavaScript Visualized: the JavaScript Engine

As JavaScript devs, we usually don't have to deal with compilers ourselves. However, it's definitely good to know the basics of the JavaScript engine and see how it handles our human-friendly JS code, and turns it into something machines understand! ๐Ÿฅณ

Happy coding!