Scoring quiz/excercises

Hey there, my testing website is slowly coming along. I have a user input that, upon Submit button click, checks the users answer, validates, and displays either “correct” or “incorrect”.

Ive tried a few different methods of keeping a score for the user, and having the sum of correct answers and total questions answered displayed on the page. No success for either just yet.

Any suggestions?

Hi Dan,

If you want the answers to be saved permanently ( maybe you want information about each user answers ) you can save the answers and the id in a Database, take a look at this documentation about inserting data.
But if you only want the final result and the number of question, i suggest you to use Sessions to save the data, Read about Sessions - Here

Good Luck,
Mustafa

Alright i think inserting data into a database would be the way to go, as it can track all user progress. Does the id created for each result mean that there could be a database where each unique users progress is stored and can be called upon on their own member page? If there is a way for a specific member user to be able to pull past results from specific tests or units that would be exactly what I need to make use of. However Im feeling a bit lost, Im sure the answer is simple but sometimes the documentation can feel a bit vague on a case by case basis

Here is what I have so far:

import wixData from ‘wix-data’;

let sumCorrect = 0
let sumTotal = 0

$w.onReady( function () {
// clear any filters in the dataset
$w(“#dynamicDataset”).setFilter(wixData.filter());

// get size of collection that is connected to the dataset
let count = $w(“#dynamicDataset”).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(“#dynamicDataset”).setCurrentItemIndex(idx);

});

// submit button click triggers validation, respective response, and respective additions for total correct
// and total answered
export function submitButton1_click_1() {
$w(“#input1”).onCustomValidation((value => {
if ($w(“#input1”).value === $w(“#answerC”).text) {
$w(“#incorrect”).hide();
$w(“#correct”).show();
$w(“#answerC”).show();
$w(“#nextButton2”).show();

        sumCorrect++ 
        sumTotal++ 

    }  **else**  { 
        $w("#correct").hide(); 
        $w("#incorrect").show(); 
        $w("#answerC").show(); 
        $w("#nextButton2").show(); 

        sumTotal++ 
    } 
})); 

}