jsPsych/examples/jspsych-categorize.html
2013-11-11 09:50:10 -05:00

103 lines
3.4 KiB
HTML

<!doctype html>
<html>
<head>
<title>jspsych-categorize plugin example</title>
<!-- jQuery -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<!-- jsPsych -->
<script src="scripts/jspsych.js"></script>
<script src="scripts/plugins/jspsych-text.js"></script>
<script src="scripts/plugins/jspsych-categorize.js"></script>
<!-- style -->
<style>
#jspsych_target {
margin: 50px auto 50px auto;
width: 600px;
font-size:18px;
text-align: center;
}
#instructions {
text-align: left;
}
#stimulus {
width: 150px;
height: 150px;
background-color: #ddd;
font-size:124px;
font-family:'Impact';
margin: auto;
}
.prompt {
font-size:14px;
}
pre {
text-align: left;
}
</style>
</head>
<body>
<div id="jspsych_target"></div>
</body>
<script type="text/javascript">
// number of trials
var n_trials = 6;
// this is an example of using HTML objects as stimuli.
// you could also use images.
var numbers = ["1", "2", "3", "4", "5"];
var letters = ["I", "Z", "B", "A", "S"];
var stimuli = [];
var answers = [];
var text_answers = [];
// randomly choose stimuli
for (var i = 0; i < n_trials; i++) {
if (Math.floor(Math.random() * 2) === 0) {
// pick a number
stimuli.push("<div id='stimulus'><p>" + numbers[Math.floor(Math.random() * numbers.length)] + "</p></div>");
answers.push(81);
text_answers.push("number");
}
else {
// pick a letter
stimuli.push("<div id='stimulus'><p>" + letters[Math.floor(Math.random() * letters.length)] + "</p></div>");
answers.push(80);
text_answers.push("letter");
}
}
// create categorization block for jspsych
var categorization_block = {
type: 'categorize',
stimuli: stimuli,
key_answer: answers,
text_answer: text_answers,
choices: [80, 81],
correct_text: "<p class='prompt'>Correct, this is a %ANS%.</p>",
incorrect_text: "<p class='prompt'>Incorrect, this is a %ANS%.</p>",
is_html: true,
prompt: "<p class='prompt'>Press P for letter. Press Q for number.</p>"
};
// create a block of instructions
var instructions_block = {
type: 'text',
text: ["<div id='instructions'><p>Press P if you see a letter. Press Q if you see a number.</p><p>Press ENTER to begin.</p></div>"]
};
// launch jspsych experiment
jsPsych.init({
display_element: $('#jspsych_target'),
experiment_structure: [instructions_block, categorization_block],
on_finish: function(data) {
$('#jspsych_target').append($("<pre>", {
text: JSON.stringify(data, undefined, 2)
}));
}
});
</script>
</html>