Solved
Subtractive Scoring of Question Responses
I'm trying to create an interaction within a question that would score the question based on how many times it takes for the user to select the "correct" answer. I've set the item scores so the correct answer is 5 and the incorrect answers are -1. I just cannot figure out how to code the question so the users score would reflect the number of times it took for the user to reach the correct. Example: First response incorrect = -1; second response incorrect = -1; third response correct = 5 - (incorrect response 1 + incorrect response 2).
Does that make sense? I'm honestly not the best at coding. I know the logic (at least how I'm thinking about it), but not how to make it happen from a code perspective.
Thank you for your time,
Amanda
Best answer by Anonymous
Hello @alealbright ,
The above requirement is acheived using MultiChoice ( Single answer ) question type and Custom code (JS):
Please follow the below steps:
Step 1: Create an embedded variable( eg: SC_Q1 ) for each question as the first element in the survey flow to store score of each question.
Step 2: Paste the below code in the js(onReady)
var CorrectAnswer = "3"; //choice number of correct choice
var that = this.questionId;
var sc=0;
jQuery("span.LabelWrapper label span").text("");
jQuery("#"+that+" input[type='radio']").on('click',function(){
if(jQuery(this).prop("checked")==true){
if(jQuery(this).attr("choiceid")==CorrectAnswer){
jQuery("#"+that+" input[type='radio']").parent().css("pointer-events","none");
jQuery(this).parent().find("span.LabelWrapper label span").html("★");
Qualtrics.SurveyEngine.setEmbeddedData('SC_Q1',(5-sc));
}else{
sc=sc+1;
jQuery(this).parent().css({"pointer-events":"none","background-color":"lightgrey"});
jQuery(this).parent().find("span.LabelWrapper label span").text("Scrathed, try another");
}
}
});
Please find the attached QSF for reference and for test link click here
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
