jsPsych version (e.g. 7.3.1): 6.3.0
I had previously been using jPsych 4 and I had written a conditional timeline where if a participant responds to a survey-multi-item with a particular response, they’d see one question but if they responded a different way, then the next question they saw would be different. E.g. “Would you say that you are a Democrat, Republican, or neither?” If they responded with Republican, then they see the question “Would you say that you are a strong Republican or a not so strong Republican”. This worked just fine, but now it doesn’t. I am wondering what changed. How can I bring back my conditional timeline??
When looking at console.log(), it keeps throwing an error saying that it can’t parse [object OBJECT]
.
Below, I have code demonstrating this:
// create timeline
var timeline = [];
// conditional timeline questions
var pid_3={
type:'survey-multi-choice',
questions:[{
//name: 'pid_3',
prompt: 'Generally speaking, do you usually think of yourself as a Democrat, a Republican, an Independent, or what?',
options:['Republican','Democrat','Independent','Other']
}]
};
//**** If they responded to previous answer with Republican, then show them this page
//***** Note: to help with figuring this out, I removed the if-else statement and used console.log(resp)
var pid_r_str={
timeline:[{
type:'survey-multi-choice',
questions:[{
name:'pid_r_str',
prompt: 'Would you say that you are a strong Republican or a not every strong Republican?',
options:[
'Strong',
'Not very strong'
]
}]
}],
conditional_function: function(){
//get data from previous trial
//show this page if Republican selected
var data=jsPsych.data.get().last(1);
var obj=JSON.parse(data.values()[0].responses);
var resp=Object.values(obj)[1];
if(resp=="Republican"){
return true;
} else{
return false;
}
}
};
//**** If they responded to pid_3 with Democrat, then show them this page
//***** Note: to help with figuring this out, I removed the if-else statement and used console.log(resp)
var pid_d_str={
timeline:[{
type:'survey-multi-choice',
questions:[{
name:'pid_d_str',
prompt:'Would you say that you are a strong Democrat or a not very strong Democrat?',
options:[
'Strong',
'Not very strong'
]
}]
}],
conditional_function: function(){
//get data from pid_3 trial
//show this page if Democrat is selected
var data=jsPsych.data.get().last(1);
var obj=JSON.parse(data.values()[0].responses);
var resp=Object.values(obj)[1];
if(resp=="Democrat"){
return true;
} else {
return false;
}
}
};
//**** If they responded to pid_3 with Independent or Other, then show them this page
//***** Note: to help with figuring this out, I removed the if-else statement and used console.log(resp)
var ind_lean={
timeline:[{
type:'survey-multi-choice',
questions:[{
name:'ind_lean',
prompt:'Do you think of yourself as closer to the Republican party or to the Democratic party?',
options:[
'Closer to Republican party',
'Neither',
'Closer to Democratic'
]
}]
}],
conditional_function: function(){
//get data from pid_3 trial
//show this page if Independent or Other is selected
var data=console.log(jsPsych.data.get().last(1));
var obj=JSON.parse(data.values()[0].responses);
var resp=Object.values(obj)[1];
if(resp=="Independent" || resp=="Other"){
return true;
} else {
return false;
}
}
};
// make array for timeline
timelineArray = [pid_3,pid_d_str,pid_r_str,ind_lean]
// push timeline
timeline.push()
//init jspsych
jsPsych.init({
timeline:timeline,
on_finish: function() {
jsPsych.data.displayData()
}
})