Adding variables to jsPsych script

Viewed 25

Adding several variables within a Jspsych-script

Hey,

I'm experimenting with jspsych and I can get the two first variables to run but when I add the last variable (the "var trial =") nothing appears when I open the HTML output. Can somebody help me with what I've done wrong? :D Did I place the 'jsPsych.run(timeline);' in the wrong place? I've added the code below.

/* initialize jsPsych */
var jsPsych = initJsPsych();

/* create timeline */
var timeline = [];

/* define welcome message trial */
var welcome = {
  type: jsPsychHtmlKeyboardResponse,
  stimulus: "Welcome to the experiment. Press any key to begin."
};
timeline.push(welcome);

/* start the experiment */
/* define instructions trial */
var instructions = {
  type: jsPsychHtmlKeyboardResponse,
  stimulus: `
        <p>In this experiment, a circle will appear in the center 
        of the screen.
        <p>Press any key to begin.</p>
      `,
  post_trial_gap: 2000
};
timeline.push(instructions);

var trial = {
  type: jsPsychSurveyMultiChoice,
  questions: [{
      prompt: "Which of the following do you like the most?",
      name: 'VegetablesLike',
      options: ['Tomato', 'Cucumber', 'Eggplant', 'Corn', 'Peas'],
      required: true
    },
    {
      prompt: "Which of the following do you like the least?",
      name: 'FruitDislike',
      options: ['Apple', 'Banana', 'Orange', 'Grape', 'Strawberry'],
      required: false
    }
  ],
};
timeline.push(trial);

/* run the experiment */
jsPsych.run(timeline);
<script src="https://unpkg.com/jspsych@7.2.3"></script>
<script src="https://unpkg.com/@jspsych/plugin-survey-multi-choice@1.1.1"></script>
<script src="https://unpkg.com/@jspsych/plugin-html-keyboard-response@1.1.1"></script>
<link href="https://unpkg.com/jspsych@7.2.3/css/jspsych.css" rel="stylesheet" type="text/css" />

0 Answers
Related