-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo_1.html
78 lines (71 loc) · 2.55 KB
/
demo_1.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<!DOCTYPE html>
<html>
<head>
<title>My experiment</title>
<script src="https://unpkg.com/jspsych@7.3.4"></script>
<script src="https://unpkg.com/@jspsych/plugin-html-keyboard-response@1.1.3"></script>
<script src="https://unpkg.com/@jspsych/plugin-html-button-response@1.1.3"></script>
<link href="https://unpkg.com/jspsych@7.3.4/css/jspsych.css" rel="stylesheet" type="text/css" />
</head>
<body></body>
<script>
const jsPsych = initJsPsych({
on_finish: function() {
jsPsych.data.displayData(); // for debugging
}
});
let timeline = [];
const welcome = {
type: jsPsychHtmlKeyboardResponse,
stimulus: "Welcome to the experiment. Press SPACE to begin."
};
timeline.push(welcome);
const instructions = {
type: jsPsychHtmlButtonResponse,
stimulus: 'Go on to the next page.',
choices: ['Next'],
post_trial_gap: 2000
};
timeline.push(instructions);
const test_stimuli = [
{ stimulus: "0", correct_response: " " },
{ stimulus: "1", correct_response: "null" },
{ stimulus: "2", correct_response: "null" }
];
const test = {
type: jsPsychHtmlKeyboardResponse,
stimulus: jsPsych.timelineVariable('stimulus'),
trial_duration: 2000,
post_trial_gap: 500,
choices: [" ", "null"],
data: {
task: 'response',
correct_response: jsPsych.timelineVariable('correct_response')
},
on_finish: function(data){
data.correct = jsPsych.pluginAPI.compareKeys(data.response, data.correct_response);
}
}
const test_procedure = {
timeline: [test],
timeline_variables: test_stimuli,
randomize_order: true, // randomize the order of the stimuli
repetitions: 5 // repeat each stimulus
}
timeline.push(test_procedure);
const debrief_block = {
type: jsPsychHtmlKeyboardResponse,
stimulus: function() {
var trials = jsPsych.data.get().filter({task: 'response'});
var correct_trials = trials.filter({correct: true});
var accuracy = Math.round(correct_trials.count() / trials.count() * 100);
var rt = Math.round(correct_trials.select('rt').mean());
return `<p>You responded correctly on ${accuracy}% of the trials.</p>
<p>Your average response time was ${rt}ms.</p>
<p>Press any key to complete the experiment. Thank you!</p>`;
}
};
timeline.push(debrief_block);
jsPsych.run(timeline);
</script>
</html>