Exiting survey based on embedded data | XM Community
Skip to main content

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();
    }
});

@rma703 Where do you get this Qualtrics.SurveyEngine.quit(); ?. I don’t believe this is the correct way to exit a survey.


@dxconnamnguyen i got that code from chat gpt….


@dxconnamnguyen i got that code from chat gpt….

Oh I remember you.
Custom coding is not always just copy&paste and chatGPT generate response base on your input.

GPT doesn’t know the qualtrics function, your survey structure, etc… you even have randomization in it.

I already gave you a complete solution that I tested in your previous topic without any complex coding. I suggest you go back and give it a try. I’ll be ready to help


Hi @dxconnamnguyen I am a newbie and was not sure how to use what you posted to write code. I’ve never used the looping feature before. Not sure if it matters, but I also don’t want participants to do the same problem over, just show them additional. So, for some participants that could take 3 problems, for a different participant it could take 10. Not sure how if that is okay with the looping


Hi @dxconnamnguyen I am a newbie and was not sure how to use what you posted to write code. I’ve never used the looping feature before. Not sure if it matters, but I also don’t want participants to do the same problem over, just show them additional. So, for some participants that could take 3 problems, for a different participant it could take 10. Not sure how if that is okay with the looping

Settle the survey in your head first. Is that necessary?  You said you're a newbie and you’re already struggle with a complex build. More feature and flexibility don’t help you here


Leave a Reply