Percentage of correct answers in a multi select type question | XM Community
Skip to main content
Question

Percentage of correct answers in a multi select type question


Forum|alt.badge.img+5

I have a multiple answer type question used and have 10 options out of which 5 options are correct. There is a validation that 5 options needs to be selected and it is setup. Now, I want to show the percentage of correct options selected when a respondant selects the choices. How is this feasible?

2 replies

Aanurag_QC
QPN Level 5 ●●●●●
Forum|alt.badge.img+31
  • 256 replies
  • September 11, 2023

Forum|alt.badge.img+3
  • 21 replies
  • September 14, 2023

In your survey flow, add a JavaScript element after the multiple-answer question. You’ll need to use JavaScript to calculate the percentage of correct options selected based on the embedded data.
 

use this JavaScript code for your reference :

Qualtrics.SurveyEngine.addOnload(function() {
    // Define the correct answers and the respondent's selected answers from embedded data
    var correctAnswers = ['Option1', 'Option2', 'Option3', 'Option4', 'Option5']; // Replace with your correct answer choices
    var selectedAnswers = ${e://Field/SelectedChoices}; // Replace with the embedded data field for selected choices

    // Convert the selected choices into an array
    selectedAnswers = selectedAnswers.split(',');

    // Calculate the percentage of correct options selected
    var correctCount = 0;
    for (var i = 0; i < selectedAnswers.length; i++) {
        if (correctAnswers.includes(selectedAnswers[i])) {
            correctCount++;
        }
    }

    var percentageCorrect = (correctCount / correctAnswers.length) * 100;

    // Display the percentage to the respondent
    jQuery('#your-question-QID').after('<p>Percentage of Correct Options Selected: ' + percentageCorrect + '%</p>');
});


Be sure to replace 'Option1', 'Option2', 'Option3', 'Option4', 'Option5' with the actual correct answer choices for your question, and replace 'your-question-QID' with the actual Question ID of your multiple-answer question.
 This JavaScript code will calculate the percentage of correct options selected by the respondent and display it after the multiple-answer question.