Hey, I’m trying to use wix code to create a multiple choice question quiz. I have a database called MCQ where every item is a question and there are fields containing both right and wrong answers as well as other information to be used or displayed.
I have a field called rightAnswer which stores values 1-4 based on which of the four answers is right for that question, and a field called userAnswer which takes in a user submitted value from 1-4 using radio buttons and the submit button on the actual web page. (Note: while they use numbers both fields are text values because that is the format for radio button values)
Having received an answer from the user, I want to be able to compare the two values and then pop-up a “right” or “wrong” message, but I’m struggling with being able to retrieve a specific field for a given data item.
I started with something like this:
import wixData from ‘wix-data’;
var userAns = null;
var rightAns = null;
export function submit_click(event) {
userAns = wixData.get("MCQ", "userAnswer");
rightAns = wixData.get(“MCQ”, “rightAnswer”);
console.log("user Answer after:",userAns, "right answer after:", rightAns);
if (userAns === rightAns)
$w(‘#right’).show();
else
$w(‘#wrong’).show();
}
But I know this is incorrect because the get() function retrieves entire items. I’ve been trying to use the query() function but I’m not sure how to do that. How do I retrieve the userAnswer and rightAnswer data fields for a given specific item?