Hello freeCodeCamp Community,
I am trying to create an app that allows a user to take multiple choice quiz. I am stuck at how to match the users chosen answers with the correct answers in MongoDB. Below is the relevant part of my code so far. Please help. Thank you.
app.route('/submit')
.post((req, res) => {
let userAnswers = req.body;
console.log(userAnswers);
//pull database of answers and check them
Ques.find({}, (err, doc)=>{
console.log(doc);
})
res.redirect('/');
})``
The result of console.log(userAnswers) is below:
``
{ 'ans-0': 'The Terminator',
'ans-1': 'SitePoint',
'ans-2': 'Sitting in a tree' }
The result of console.log(doc) is below:
[{ _id: 5be0d64b15018a580407660b,
question: 'Who is the strongest?',
answers: { a: 'Superman', b: 'The Terminator', c: 'Waluigi, obviously' },
correctAnswer: 'c' }
{ 'ans-0': 'Waluigi, obviously',
'ans-1': 'Simple Steps Code',
'ans-2': 'Exploring the Pacific Ocean' }
{ _id: 5be0d64b15018a580407660b,
question: 'Who is the strongest?',
answers: { a: 'Superman', b: 'The Terminator', c: 'Waluigi, obviously' },
correctAnswer: 'c' }]