-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathgonogo.html
108 lines (94 loc) · 3.28 KB
/
gonogo.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<!doctype html>
<html>
<head>
<title>My experiment</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<!-- Just using this to get touch events, so no CSS -->
<script src="https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.js"></script>
<script src="jspsych-4.3/jspsych.js"></script>
<script src="jspsych-4.3/plugins/jspsych-text.js"></script>
<script src="jspsych-4.3/plugins/jspsych-single-stim.js"></script>
<link href="jspsych-4.3/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='/images/blue.png'></img>" +
"<p class='small'><strong>Press the F key</strong></p></div>" +
"<div class='right center-content'><img src='/images/orange.png'></img>" +
"<p class='small'><strong>Do not press a key</strong></p></div>" +
"<p>Press any key to begin.</p>",
timing_post_trial: 2000
};
/* define test block */
var test_stimuli = [
{
image: "/images/blue.png",
data: { response: 'go' }
},
{
image: "/images/orange.png",
data: { response: 'no-go' }
}
];
var all_trials = jsPsych.randomization.repeat(test_stimuli, 10, true);
var post_trial_gap = function() {
return Math.floor( Math.random() * 1500 ) + 750;
}
var test_block = {
type: "single-stim",
stimuli: all_trials.image,
choices: ['F'],
data: all_trials.data,
timing_response: 1500,
timing_post_trial: post_trial_gap
};
/* define debrief block */
function getAverageResponseTime() {
var trials = jsPsych.data.getTrialsOfType('single-stim');
var sum_rt = 0;
var valid_trial_count = 0;
for (var i = 0; i < trials.length; i++) {
if (trials[i].response == 'go' && trials[i].rt > -1) {
sum_rt += trials[i].rt;
valid_trial_count++;
}
}
return Math.floor(sum_rt / valid_trial_count);
}
var debrief_block = {
type: "text",
text: function() {
return "<p>Your average response time was <strong>" +
getAverageResponseTime() + "ms</strong>. Press " +
"any key to complete the experiment. Thank you!</p>";
}
};
/* create experiment definition array */
var experiment = [];
experiment.push(welcome_block);
experiment.push(instructions_block);
experiment.push(test_block);
experiment.push(debrief_block);
/* start the experiment */
jsPsych.init({
experiment_structure: experiment,
on_finish: function() {
jsPsych.data.displayData();
}
});
</script>
</html>