Creating Randomized Quiz

Hey there everyone,

Very new to coding, but I am trying to create a site with randomized quizzes and exercises. I understand that quizzes can be created through box slideshows which are converted to multi stage forms. What I would like to do is have the variables for specific questions be selected from the database to create randomized testing. Example: X + Y = Z so X and Y are pulled from Column X and Y from the database and Column Z is checked against the users input to determine correct or incorrect response.

This would save me from having to make potentially thousands of individual slides to ensure a unique user testing experience. I was super excited to see these new wix code features would make this a possibility, but Im a tad overwhelmed as im a complete noob.

Any help or guidance would be so greatly appreciated and would be rewarded with pictures of my cat if you so desire.

Thanks in advance

Hey Dan,

Take a look at the forum post Randomize Dataset Selection . My answer to that post has a very simple random dataset lookup which should help you get started. Play with it a bit and if you need help adapting to your use then let me know.

Good luck,

Yisrael

This is great thank you. I was able to get the variables of the question to randomly select from the dataset, now Im wondering about the user input part. I found another user’s question about making a language quiz and saw his code for having different outcomes based on the user input. (here is the link for reference: https://www.wix.com/code/home/forum/questions-answers/validation-textinput-when-enter-is-hit

. He has an “if” function to determine the outcome for a specific word in the user input box, and the “else” part says all the stuff that happens if they get any other answer. Easy enough to switch out the Dutch words for all the relevant IDs for my page.

This works for a predetermined answer for one question, but i was wondering how i could go about re appropriating the code to reference the appropriate answer from the dataset based on the randomly generated question variables that would go with it.

Here is a photo of my cat as promised

Hi,
If I understand correctly, you wish to have a multilingual quiz?
If so, I recommend checking out this thread . Instead of updating the labels of the buttons (in the examples), you can set the text property of a text box. If this is not what you were referring, please clarify what you would like to achieve. You can add screenshots to better explain it.

Cute cat by the way :wink:

Best,
Tal.

Hey Tal

Thank you but no I should specify that my website will be for music theory education.

Yisreal helped me with this for randomizing the selections from a dataset:
import wixData from ‘wix-data’;

// clear any filters in the dataset
$w(“#dataset1”).setFilter( wixData.filter() );

// get size of collection that is connected to the dataset
let count = $w(“#dataset1”).getTotalCount();

// get random number using the size as the maximum
let idx = Math.floor(Math.random() * count);

// set the current item index of the dataset
$w(“#dataset1”).setCurrentItemIndex(idx);

This much helps me to have the variables in each question be different each time. Kind of like a self generating quiz

So here is an example question:

Question
What is the
“5th”
note in the key of
“C Major”?

Answer
“G”

What I am looking for is to have a user input box that can cross reference the dataset and see that the input either matches the appropriate answer or does not. I have found the language quiz post in the coding forum which could be a huge help, but the code he has would require using the specific answer in the code for every question. In my case this could lead to me doing this 1500 times for each possible iteration for each type of question. And there will be many more types of questions

His code for his language quiz is this:

export function controleer2_click() {
$w(“#textInput3”).onCustomValidation( (value) => {
if(value === “la”) {
$w(“#volgendebutton2”).show();
$w(“#uiteg2”).show();
$w(“#line10”).hide();
$w(“#antwoordbutton2”).hide();
$w(“#nogeens2”).hide();
$w(“#textInput3”).disable();}
else {
$w(“#line10”).show();
$w(“#uiteg2”).show();
$w(“#nogeens2”).expand();
$w(“#antwoordbutton2”).expand();}
});

Simple enough for me to plug in my own page elements IDs in place of the Dutch words. My focus is this part here:

if(value === “la”)

If i can replace the very specific “la” with some type of scripting (that can cross reference user input against what is in the appropriate answer column of my dataset) then I can have a self generating/self marking quiz and drill machine. That would save me literal days at the computer as well as many nights crying myself to sleep. But most importantly it would create a completely unique user experience every single time they log in.

Hopefully Im making sense here, as I said im very new to this but I feel like this is possible with a bit of know how and guidance

Thanks again for the help everyone

For what it’s worth, I’m trying to do the same exact thing 2 years later. Lol