I am currently working on developing an experiment using the JSPsych JavaScript package. The main goal of my experiment is for participants to input a letter in a survey-text trial, and then have that same letter presented back to them as a stimulus in the following html-response trial.
One issue I am facing is finding a way to access the participant's input from the survey-text trial. My program structure is following the reaction time tutorial from the JSPsych website, where trials are created sequentially and pushed into a timeline array at the end of the code. This means that when the trials are defined, the participant has not inputted anything yet.
Below is the code snippet I am using. While testing the experiment in a browser, I have been able to access the data from the survey-text trial using
JSON.parse(jsPsych.data.getLastTrialData().select('responses').values).favorite
. However, this code snippet produces an error: SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data
. This error occurs because, at the time the code is compiled, there is no previous trial data to retrieve.
let letter_display, letter_survey, test_procedure, timeline;
timeline = [];
letter_survey = {
type: "survey-text",
questions: [
{prompt: "What is your favorite letter?", name:"favorite"}
],
}
timeline.push(letter_survey);
letter_display = {
type: 'html-keyboard-response',
stimulus: jsPsych.timelineVariable('stimulus'),
};
test_procedure = {
timeline: [letter_display],
timeline_variables: [{type:'html-keyboard-response', stimulus: JSON.parse(jsPsych.data.getLastTrialData().select('responses').values).favorite}]
};
timeline.push(test_procedure);
jsPsych.init({
timeline: timeline
})