jsPsych/examples/jspsych-single-stim.html
2013-11-12 13:45:51 -05:00

76 lines
2.5 KiB
HTML

<!doctype html>
<html>
<head>
<title>jspsych-single-stim example</title>
<!-- Load jQuery -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<!-- Load the jspsych library and plugins -->
<script src="scripts/jspsych.js"></script>
<script src="scripts/plugins/jspsych-text.js"></script>
<script src="scripts/plugins/jspsych-single-stim.js"></script>
<!-- style -->
<style>
#jspsych_target {
margin: 50px auto 50px auto;
width: 600px;
font-size:18px;
text-align: center;
}
#instructions {
text-align: left;
}
pre {
text-align: left;
}
</style>
</head>
<body>
<div id="jspsych_target"></div>
</body>
<script type="text/javascript">
// Experiment parameters
var n_trials = 6;
var stimuli = ["img/congruent_left.gif", "img/congruent_right.gif", "img/incongruent_left.gif", "img/incongruent_right.gif"];
// Experiment Instructions
var instructions = '<div id="instructions"><p>You will see a series of images that look similar to this:</p>\
<p><img src="img/incongruent_right.gif"></p><p>Press the arrow key that corresponds to the direction that\
the middle arrow is pointing. For example, in this case you would press the right arrow key.</p>\
<p>Press enter to start.</p>';
// Generating Random Order for Stimuli
var stimuli_random_order = [];
for (var i = 0; i < n_trials; i++) {
var random_choice = Math.floor(Math.random() * stimuli.length);
stimuli_random_order.push(stimuli[random_choice]);
}
// Define experiment blocks
var instruction_block = {
type: "text",
text: [instructions],
timing_post_trial: 1000
};
var test_block = {
type: "single-stim",
stimuli: stimuli_random_order,
choices: [37, 39]
};
jsPsych.init({
display_element: $('#jspsych_target'),
experiment_structure: [instruction_block, test_block],
on_finish: function(data) {
$("#jspsych_target").append($('<pre>', {
html: JSON.stringify(data,undefined,2)
}));
}
});
</script>
</html>