Counting correct answers | XM Community
Skip to main content

Hi,

I am hoping to run an experiment where it skips to the end of the block/section after a participant has answered 3 questions correctly. These are open-ended (not multiple choice questions). Does anyone know if this is possible? The issue (maybe) is that the order of the questions in a block is randomized. 

I think you can achieve this using JS.

First set a variable to +1 if the answer/choice is as intended and store it again by setting an embedded variable on page submit. Then check if the value is 3 in page load and if it’s yes then click next button for all the questions.

Do check all the scenarios beforehand.


@rma703 Challenge accepted, it is possible

  1. I set a loop&merge like this with all my question in field2. And randomize the order in the loop

     

  2. Set a survey with:
    1. A kick out block that skip to the end if ED: wrong answer = 3
    2. The question with loop&merger field
    3. A wrong answer announcer that contain JavaScript to +1 to ED: wronganswer (make sure you declare it = 0) at the beginning. Appear if the question textentry is wrong
      Qualtrics.SurveyEngine.addOnload(function()
      {
      let a = "${e://Field/wronganswer}";
      a++;
      Qualtrics.SurveyEngine.setEmbeddedData( 'wronganswer', a );
      });

 


@dxconnamnguyen I am very much a newbie. Could you demonstrate how to modify the code above (“Qualtrics.SurveyEngine.addOnload(function() { let a = "${e://Field/wronganswer}"; a++; Qualtrics.SurveyEngine.setEmbeddedData( 'wronganswer', a ); });” if the right answer is .20?


@dxconnamnguyen I am very much a newbie. Could you demonstrate how to modify the code above (“Qualtrics.SurveyEngine.addOnload(function() { let a = "${e://Field/wronganswer}"; a++; Qualtrics.SurveyEngine.setEmbeddedData( 'wronganswer', a ); });” if the right answer is .20?

No, let that code be it.
The condition of the text/graphic ques wronganswer ++ should be the one you change to. Eg Q1 answer is .20, Q2 answer is .50. The display logic of the JS code shouldbe If Q1 text response is not equal to.20 or Q2 text response is not equal to.50

 


Set up skip logic to conditionally skip to the end of the block/section when the “CorrectAnswers” embedded data reaches 3.

Here’s a simplified example of JavaScript code that increments “CorrectAnswers” when a correct answer is given:

Qualtrics.SurveyEngine.addOnload(function() {
    var isCorrect = /* Your condition to check if the answer is correct */;

    // If it's correct, increment CorrectAnswers
    if (isCorrect) {
        var currentCorrectAnswers = parseInt("${e://Field/CorrectAnswers}", 10);
        currentCorrectAnswers += 1;
        Qualtrics.SurveyEngine.setEmbeddedData("CorrectAnswers", currentCorrectAnswers.toString());
    {
    if (parseInt("${e://Field/CorrectAnswers}", 10) >= 3) {
        this.question.clickNextButton();
    }
});


@Qual.78500 Does this allow for multiple correct answers? In that there are multiple problems with different answers, but also that someone could say .4 instead of .40 for instance


Okay so I have code that sort of works---it is counting correct answers, but it is not exiting the survey when the criterion is hit (3). Does anyone know what is wrong with my code?

 

Qualtrics.SurveyEngine.addOnload(function() {
    var isCorrect = 4;
    var currentCorrectAnswers = Qualtrics.SurveyEngine.getEmbeddedData("CorrectAnswers");
    
    if (!currentCorrectAnswers) {
        currentCorrectAnswers = 0;
    }

    // If it's correct, increment CorrectAnswers
    if (isCorrect) {
        currentCorrectAnswers++;
        Qualtrics.SurveyEngine.setEmbeddedData("CorrectAnswers", currentCorrectAnswers.toString());
    }

    if (currentCorrectAnswers >= 3) {
        Qualtrics.SurveyEngine.quit();
    }
});


Leave a Reply