Displaying stimuli in a lexical decision task

155 views
Skip to first unread message

Orhan Bilgin

unread,
Apr 29, 2015, 10:48:07 AM4/29/15
to jsp...@googlegroups.com
Hi all,

I am new to both JavaScript and jspsych, so, my question is a little too basic. Sorry about that.

I am trying to modify the code of the "Go / No-Go" demo experiment in order to display textual stimuli (actually, single words) instead of images. The documentation says that the single-stim plugin can be used to display images or any HTML content, but I have been unable to display any words so far. How can I modify the tutorial code to achieve this?

Best,

Orhan

Josh de Leeuw

unread,
Apr 29, 2015, 10:51:32 AM4/29/15
to Orhan Bilgin, jsp...@googlegroups.com
Hi, Orhan.

Here's the 'complete code' from Step 4 of the go/no-go demo, modified to display words. The key change is in the definition of the test_block. First, I changed the stimuli array to contain words instead of paths to images. Second, I added the parameter "is_html" and set it to true.

<!doctype html>
<html>
  <head>
    <title>My experiment</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script src="jsPsych-4.0/jspsych.js"></script>
    <script src="jsPsych-4.0/plugins/jspsych-text.js"></script>
    <script src="jsPsych-4.0/plugins/jspsych-single-stim.js"></script>
    <link href="jsPsych-4.0/css/jspsych.css" rel="stylesheet" type="text/css"></link>
  </head>
  <body>
  </body>
  <script>

    /* define welcome message block */
    var welcome_block = {
      type: "text",
      text: "Welcome to the experiment. Press any key to begin."
    };

    /* define instructions block */
    var instructions_block = {
      type: "text",
      text: "<p>In this experiment, a circle will appear in the center " +
          "of the screen.</p><p>If the circle is <strong>blue</strong>, " +
          "press the letter F on the keyboard as fast as you can.</p>" +
          "<p>If the circle is <strong>orange</strong>, do not press " +
          "any key.</p>" +
          "<div class='left center-content'><img src='static/images/blue.png'></img>" +
          "<p class='small'><strong>Press the F key</strong></p></div>" +
          "<div class='right center-content'><img src='static/images/orange.png'></img>" +
          "<p class='small'><strong>Do not press a key</strong></p></div>" +
          "<p>Press any key to begin.</p>"
    };

    /* define test block */
    var test_block = {
      type: "single-stim",
      stimuli: ['dog', 'cat'],
      choices: ['W','N'],
    };

    /* create experiment definition array */
    var experiment = [];
    experiment.push(welcome_block);
    experiment.push(instructions_block);
    experiment.push(test_block);

    /* start the experiment */
    jsPsych.init({
      experiment_structure: experiment
    });
  </script>
</html>

--
You received this message because you are subscribed to the Google Groups "jsPsych" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jspsych+u...@googlegroups.com.
To post to this group, send email to jsp...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jspsych/65800749-adf5-485c-b666-638d046bef24%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Josh de Leeuw

unread,
Apr 29, 2015, 10:52:55 AM4/29/15
to Orhan Bilgin, jsp...@googlegroups.com
I sent that last message prematurely by accident. Here's the complete code. (I also changed the 'choices' parameter to allow for responses of W and N for word and non-word.

"></script>
    <script src="jsPsych-4.0/jspsych.js"></script>
    <script src="jsPsych-4.0/plugins/jspsych-text.js"></script>
    <script src="jsPsych-4.0/plugins/jspsych-single-stim.js"></script>
    <link href="jsPsych-4.0/css/jspsych.css" rel="stylesheet" type="text/css"></link>
  </head>
  <body>
  </body>
  <script>

    /* define welcome message block */
    var welcome_block = {
      type: "text",
      text: "Welcome to the experiment. Press any key to begin."
    };

    /* define instructions block */
    var instructions_block = {
      type: "text",
      text: "<p>In this experiment, a circle will appear in the center " +
          "of the screen.</p><p>If the circle is <strong>blue</strong>, " +
          "press the letter F on the keyboard as fast as you can.</p>" +
          "<p>If the circle is <strong>orange</strong>, do not press " +
          "any key.</p>" +
          "<div class='left center-content'><img src='static/images/blue.png'></img>" +
          "<p class='small'><strong>Press the F key</strong></p></div>" +
          "<div class='right center-content'><img src='static/images/orange.png'></img>" +
          "<p class='small'><strong>Do not press a key</strong></p></div>" +
          "<p>Press any key to begin.</p>"
    };

    /* define test block */
    var test_block = {
      type: "single-stim",
      stimuli: ['dog', 'cat'],
      choices: ['W','N'],
      is_html: true
    };

    /* create experiment definition array */
    var experiment = [];
    experiment.push(welcome_block);
    experiment.push(instructions_block);
    experiment.push(test_block);

    /* start the experiment */
    jsPsych.init({
      experiment_structure: experiment
    });
  </script>
</html>

Orhan Bilgin

unread,
Apr 29, 2015, 11:01:44 AM4/29/15
to jsp...@googlegroups.com, or...@zargan.com
Thank you for this amazingly fast and helpful support :) 

I will definitely mention you in the acknowledgments section of my master's thesis here at Bosphorus University, Istanbul. Great library, thanks!

Best,

Orhan
Reply all
Reply to author
Forward
0 new messages