I don't know how to use conditional #2068
-
Hi! I find myself stuck in a problem that surely is easy to solve. The situation is that I must create a stimulus that, depending on the participant's response, takes him to one page or another of the experiment. That is, if the subject answers "yes" to the question, then he should see a new question to answer on the screen. Instead, if his/her answer is "no", should skip that question and continue with the experiment.
After this the conditional parameter should go (I guess). If the answer to the last question was "yes", then they should answer this:
If instead the answer in "final_questions1" was "no", they should go to another survey-text that continue with the experiment. I hope I was clear in the description. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hi @ler93, you can have a look at the documentation for conditional timelines here. In your case, the There are a few different ways that you can access the data from the Here's what this looks like all together: var final_questions1 = {
type: 'html-button-response',
stimulus: 'While you were reading the phenomenon: Did you remember any of the stories read during the text comprehension activity?',
choices: ['Yes', 'No'], // 'yes' is 0, 'no' is 1
};
timeline.push (final_questions1);
// create this trial but don't add it directly to your main timeline
var final_questions2 = {
type: 'survey-text',
questions: [
{prompt: '<p> Can you describe in as much detail as possible what was the situation you remembered? </p>',
columns: 60, rows: 10, required: true, name: 'Memory of situation'}],
button_label: 'Next>',
};
// create a conditional node that contains the final_question2 trial and a conditional function,
// and add this to the main timeline
var final_questions_conditional = {
timeline: [final_questions2],
conditional_function() {
// get the data from the last trial (final_questions1)
var last_trial_data = jsPsych.data.getLastTrialData().values()[0];
if (last_trial_data.response == 0) {
// if the response was choice 0 ("yes"), then run the conditional timeline
return true;
} else {
// otherwise skip the conditional timeline
return false;
}
}
};
timeline.push (final_questions_conditional); |
Beta Was this translation helpful? Give feedback.
Hi @ler93, you can have a look at the documentation for conditional timelines here.
In your case, the
final_questions2
trial should go inside of a conditional node, since that trial should only run under certain conditions. In theconditional_function
for your conditional node, you'll want to check what choice was made on thefinal_questions1
trial. The conditional function should returntrue
if "yes" was selected, and should returnfalse
if "no" was selected.There are a few different ways that you can access the data from the
final_questions1
trial. One option is to get all of the jsPsych data withjsPsych.data.get
, and then filter the resulting data collection with thefilter
function.…