You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi all, I have been trying to write an adaptive test with jsPsych using the loop_function and the conditional_function.
Here is what I want to achieve:
"Start from Item 1. Item 1 and item 4 are in Loop 1. Item 2 and Item 5 are in Loop 2.
If Item 1 is correct, feedback saids "Correct" and end Loop 1. Jump to Item 2.
If Item 1 is incorrect, feedback saids "Incorrect" and jump to Item 4.
If Item 4 is correct, feedback saids "Correct" and end Loop 1 and jump to Item 2.
If Item 4 is incorrect, feedback saids "Incorrect, try again" and repeat 4.
If Item 4 is incorrect again, feedback saids "Incorrect, please think of the comment features in the examples. Try again." and repeat 4.
If Item 4 is incorrect the third time, feedback saids "Incorrect, the comment features in the examples are .... Try again." and repeat 4.
If Item 4 is incorrect the fourth time, feedback saids "Incorrect, the correct answer is ..." and end Loop 1. Jump to Item 5. "
But what I got now is Item 4 keep repeat no matter what I input in the text box.
I don't know which step I went wrong. I really appreciate if someone can help me figure it out. Many thanks!!
Here are my codes:
/* define loop 1 */
//define Item 1
var Item1 = {
type: jsPsychSurveyHtmlForm,
preamble: `
<img src="img/Item1.png" alt="Item1" style="float:center;width:1000px;"></img>
`,
html: '<span style = "font-size: 20px">I choose <input name = "Item1_response1" id = "test-resp-box" size:"50"/>. </span>',
autofocus:'test-resp-box',
button_label: ["submit"],
data: {
Item_type: 'Test_Item1',
Attempt: '1',
correct_response: 'C'
},
on_finish: function(data){
if (jsPsych.pluginAPI.compareKeys(data.response.Item1_response1, "C")) {
data.correct = true;
} else {
data.correct = false;
}
console.log (data.response,data.correct_response);
}
};
//define Item 1 feedback
var Item1_feedback0= {
type: jsPsychHtmlButtonResponse,
stimulus: function (){
var last_trial_correct = jsPsych.data.get().last(1).values()[0].correct;
if (last_trial_correct){
return `
<img src="img/Item1.png" alt="Item1" style="float:center;width:1100px;"></img>
<p style="color:green;">correct!</p>
`;
} else {
return `
<img src="img/Item1.png" alt="Item1" style="float:center;width:1100px;"></img>
<p style="color:red;">Incorrect!</p>
`;
}
},
choices: ['OK']
};
//define Item 4
var Item4 = {
type: jsPsychSurveyHtmlForm,
preamble: `
<img src="img/Item4.png" alt="Item4" style="float:center;width:1100px;"></img>
`,
html: '<span style = "font-size: 20px">I choose <input name = "Item4_response1" id = "test-resp-box" size:"50"/>. </span>',
autofocus:'test-resp-box',
button_label: ["submit"],
data: {
Item_type: 'Training_Item4',
Attempt: '1',
correct_response: 'E'
},
on_finish: function(data){
if (jsPsych.pluginAPI.compareKeys(data.response.Item4_response1, "E")) {
data.correct = true;
} else {
data.correct = false;
}
console.log (data.response,data.correct_response);
}
};
//define Item 4 feedback
var Item4_feedback0= {
type: jsPsychHtmlButtonResponse,
stimulus: function (){
var last_trial_correct = jsPsych.data.get().last(1).values()[0].correct;
if (last_trial_correct){
return `
<img src="img/Item4.png" alt="Item4" style="float:center;width:1100px;"></img>
<p style="color:green;">Correct!</p>
`;
} else {
return `
<img src="img/Item4.png" alt="Item4" style="float:center;width:1100px;"></img>
<p style="color:red;">Incorrect, try again!</p>
`;
}
},
choices: ['OK']
};
var Item4_feedback1a = {
type: jsPsychHtmlButtonResponse,
stimulus: function(){
var last_trial_correct = jsPsych.data.get().last(1).values()[0].correct;
if (last_trial_correct){
return `
<img src="img/Item4.png" alt="Item4" style="float:center;width:1000px;"></img>
<p style="color:green;">Correct!</p>
`;
} else {
return `
<img src="img/Item4.png" alt="Item4" style="float:center;width:1000px;"></img>
<p style = "color:red;">Incorrect. Please find out the similarities and differences in the pictures. Try again!</p>
`
;
}
},
choices: ['OK'],
};
var Item4_feedback2a = {
type: jsPsychHtmlButtonResponse,
stimulus: function(){
var last_trial_correct = jsPsych.data.get().last(1).values()[0].correct;
if (last_trial_correct){
return `
<img src="img/Item4.png" alt="Item4" style="float:center;width:1000px;"></img>
<p style="color:green;">Correct!</p>
`;
} else {
return `
<img src="img/Item4.png" alt="Item4" style="float:center;width:1000px;"></img>
<p style = "color:red;">Incorrect!</p>
<p> The similarities are trees and the second character means trees。Please try again!</p>
`
;
}
},
choices: ['OK'],
};
var Item4_feedback3a = {
type: jsPsychHtmlButtonResponse,
stimulus: function(){
var last_trial_correct = jsPsych.data.get().last(1).values()[0].correct;
if (last_trial_correct){
return `
<img src="img/Item4.png" alt="Item4" style="float:center;width:1000px;"></img>
<p style="color:green;">Correct!</p>
`;
} else {
return `
<img src="img/Item4.png" alt="Item4" style="float:center;width:1000px;"></img>
<p style = "color:red;">Incorrect! The correct answer is "E" .
`
;
}
},
choices: ['OK'],
};
var Item4_loop1 = {
timeline: [Item4,Item4_feedback1a,Item4,Item4_feedback2a,Item4,Item4_feedback3a],
loop_function: function(data){
console.log(jsPsych.data.get().last(1).values()[0]);
var data = jsPsych.data.get().last(1).values()[0];
if(jsPsych.pluginAPI.compareKeys(data.response.Item4_response1, "E")){
return false;
} else {
return true;
}
}
};
var Item4_node ={
timeline: [Item4,Item4_feedback0,Item4_loop1],
conditional_function: function (){
var data = jsPsych.data.get().last(1).values()[0];
if(jsPsych.pluginAPI.compareKeys(data.response.Item1_response1, "C")){
return false;
} else {
return true;
}
}
};
var Loop1 = {
timeline: [Item1, Item1_feedback0, Item4_node]
};
timeline.push(Loop1);
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi all, I have been trying to write an adaptive test with jsPsych using the loop_function and the conditional_function.
Here is what I want to achieve:
"Start from Item 1. Item 1 and item 4 are in Loop 1. Item 2 and Item 5 are in Loop 2.
If Item 1 is correct, feedback saids "Correct" and end Loop 1. Jump to Item 2.
If Item 1 is incorrect, feedback saids "Incorrect" and jump to Item 4.
If Item 4 is correct, feedback saids "Correct" and end Loop 1 and jump to Item 2.
If Item 4 is incorrect, feedback saids "Incorrect, try again" and repeat 4.
If Item 4 is incorrect again, feedback saids "Incorrect, please think of the comment features in the examples. Try again." and repeat 4.
If Item 4 is incorrect the third time, feedback saids "Incorrect, the comment features in the examples are .... Try again." and repeat 4.
If Item 4 is incorrect the fourth time, feedback saids "Incorrect, the correct answer is ..." and end Loop 1. Jump to Item 5. "
But what I got now is Item 4 keep repeat no matter what I input in the text box.
I don't know which step I went wrong. I really appreciate if someone can help me figure it out. Many thanks!!
Here are my codes:
Beta Was this translation helpful? Give feedback.
All reactions