Conditional loop using survey-multi-choice plugin #2646
-
Hi everyone, When executing the code, it always loops the question regardless of the answer and feedback provided. Could someone help me out on this? Any tip is appreciated. Thank you in advance! Here is the code: //compcheck 1: question and options
var comprehension_question1 = {
type: jsPsychSurveyMultiChoice,
questions: [
{prompt: '<div align=center><img src="jspsych/img/Like.bmp" width="200px"; height: "200px"></img></div>' +
'<div align=center><b>The "thumbs up" symbol indicates that:</b></div>',
options: [
'A rater likes me',
'My prediction was correct',
'A rater dislikes me',
'My prediction was incorrect'
],
required: true
},
],
preamble: "<h3>Please answer the following question.</h3>"
};
//compcheck1: this function returns feedback based on response given
var comp1_feedback = {
type: jsPsychHtmlButtonResponse,
stimulus: function(){
var data = jsPsych.data.getLastTrialData().values()[0];
var answer_Q1 = data.response.Q0;
if(answer_Q1.includes('A rater likes me')) {
return "<p><img src='jspsych/img/Like.bmp' width='200px'; height: '200px'></img></p>" +
"<p align='center'><b>CORRECT!</b> Indeed, this symbol means that a rater likes you and is interested in becoming
friends.</p>";
} else {
return "<p align='center'><img src='jspsych/img/Like.bmp' width='200px'; height: '200px'></img></p>" +
"<p align='center'><b>INCORRECT.</b> This symbol means that a rater likes you. </p>"
}
},
choices: ['Next'],
on_finish: function(data){
if(data.stimulus == "<p align='center'><b>CORRECT!</b> Indeed, this symbol means that a rater likes you and is interested in becoming friends.</p>") {
data.correct = true;
} else {
data.correct = false;
}
}
};
//compcheck1: if answer incorrect, compcheck1 will be repeated until correct response inserted
var comp1_loop = {
timeline: [comprehension_question1, comp1_feedback],
loop_function: function(data){
if (data.correct == true) {
return false
} else {
return true
}
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
Hi @miriamdietz, I'm guessing the scoring isn't working because you're using the var answer_Q1 = data.response.Q0; So try checking the response string like this: if(answer_Q1 == 'A rater likes me') { |
Beta Was this translation helpful? Give feedback.
Hi @miriamdietz, I'm guessing the scoring isn't working because you're using the
includes
Javascript function to check the response, butincludes
is meant to be called on arrays. In your case, you've retrieved the MC option that the participant selected from theresponses
object as a string:So try checking the response string like this: