mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 11:10:54 +00:00
65 lines
1.6 KiB
HTML
65 lines
1.6 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<script src="../jspsych.js"></script>
|
|
<script src="../plugins/jspsych-html-keyboard-response.js"></script>
|
|
<link rel="stylesheet" href="../css/jspsych.css">
|
|
</head>
|
|
<body></body>
|
|
<script>
|
|
|
|
var trial = {
|
|
type: 'html-keyboard-response',
|
|
stimulus: 'Hello. This is in a loop. Press "r" to repeat this trial, or "c" to continue.',
|
|
choices: ['r','c']
|
|
}
|
|
|
|
var loop_node = {
|
|
timeline: [trial],
|
|
loop_function: function(data){
|
|
var key_response = data.values()[0].response;
|
|
if(jsPsych.pluginAPI.compareKeys(key_response,'r')){
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
var pre_if_trial = {
|
|
type: 'html-keyboard-response',
|
|
stimulus: 'The next trial is in a conditional statement. Press "s" to skip it, or "v" to view it.',
|
|
choices: ['s','v']
|
|
}
|
|
|
|
var if_trial = {
|
|
type: 'html-keyboard-response',
|
|
stimulus: 'You chose to view the trial. Press any key to continue.'
|
|
}
|
|
|
|
var if_node = {
|
|
timeline: [if_trial],
|
|
conditional_function: function(){
|
|
var data = jsPsych.data.get().last(1).values()[0];
|
|
if(jsPsych.pluginAPI.compareKeys(data.response, 's')){
|
|
return false;
|
|
} else {
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
|
|
var after_if_trial = {
|
|
type: 'html-keyboard-response',
|
|
stimulus: 'This is the trial after the conditional.'
|
|
}
|
|
|
|
jsPsych.init({
|
|
timeline: [loop_node, pre_if_trial, if_node, after_if_trial],
|
|
on_finish: function(){ jsPsych.data.displayData(); },
|
|
default_iti: 200
|
|
});
|
|
|
|
</script>
|
|
</html>
|