Dear Qualtrics community,
I have a survey where I ask people to guess the percentage of women in different sector.s I want to assign to them one point for each of the correct answer.
i.e. "What is the percentage of women in Economics?" and then they have to slide a slider from 0 to 100. If they guess the correct answer, (which in this case let's say it's 48 percent) then they get one point.
Then I repeat the questions for different sectors and I calculate the total score of correct answers.
I tried to implement this code but with no success.
Qualtrics.SurveyEngine.addOnPageSubmit(function(){
let solution = 48
let sliderValue = Number(document.getElementById('QR~'+this.questionId).value);
let score1;
console.log(sliderValue)
if(solution === sliderValue){
score1 = 1
}else{
score1 = 0
}
let text1 = Qualtrics.SurveyEngine.setEmbeddedData("score1", score1)
let totalScore = Number(score1)
});
I also attach here the .qsf of the survey! Thank you very much in advance!
Gaia
Scoring_with_Sliders.qsf
For who is interested, I managed to solve the problem by putting after my slider questions an empty question with this Javascript code:
I also created the correspondent embedded field in Survey Flow (i.e. score2_2 etc.)
I basically stored the value of each slider in a variable and then sum all of the variables to create the total score. Hope this helps!
var slider2_1 = parseInt("${q://QID48/ChoiceNumericEntryValue/1}");
var slider2_2 = parseInt("${q://QID48/ChoiceNumericEntryValue/2}");
var slider2_3 = parseInt("${q://QID48/ChoiceNumericEntryValue/3}");
var slider2_4 = parseInt("${q://QID48/ChoiceNumericEntryValue/4}");
var slider2_5 = parseInt("${q://QID48/ChoiceNumericEntryValue/5}");
var slider2_6 = parseInt("${q://QID48/ChoiceNumericEntryValue/6}");
var score2_1 = 0;
var score2_2 = 0;
var score2_3 = 0;
var score2_4 = 0;
var score2_5 = 0;
var score2_6 = 0;
var totalScore2 =0;
if (slider2_1 == -17) {
score2_1 = 1;
}
if (slider2_2 == -13) {
score2_2 = 1;
}
if (slider2_3 == -10) {
score2_3 = 1;
}
if (slider2_4 == -8) {
score2_4 = 1;
}
if (slider2_5 == -6) {
score2_5 = 1;
}
if (slider2_6 == -10) {
score2_6 = 1;
}
totalScore2 = (score2_1+score2_2+score2_3+score2_4+score2_5+score2_6) //calculating the mean score
//setting the already-created embedded data variables score1, score2, score3, avgScore
Qualtrics.SurveyEngine.setEmbeddedData("score2_1", score2_1);
Qualtrics.SurveyEngine.setEmbeddedData("score2_2", score2_2);
Qualtrics.SurveyEngine.setEmbeddedData("score2_3", score2_3);
Qualtrics.SurveyEngine.setEmbeddedData("score2_4", score2_4);
Qualtrics.SurveyEngine.setEmbeddedData("score2_5", score2_5);
Qualtrics.SurveyEngine.setEmbeddedData("score2_6", score2_6);
Qualtrics.SurveyEngine.setEmbeddedData("totalScore2", totalScore);
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.