DEV Community

Cory Allen
Cory Allen

Posted on

1 1

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.

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs