-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnback_no_practice.html
More file actions
295 lines (246 loc) · 10.6 KB
/
nback_no_practice.html
File metadata and controls
295 lines (246 loc) · 10.6 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
<html>
<head>
<title>n-back test</title>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="invisible_button.css">
</head>
<body>
<div id ="instruct"> </div>
<br>
<p id = "startbutton"> </p>
<p id="yesbutton"> </p>
<p id="image"> </p>
<p id = "test_1_results_title"> </p>
<br>
<p id = "test_1_results"> </p>
<br>
<p id = "test_2_results_title"> </p>
<br>
<p id = "test_2_results"> </p>
<br>
<br>
<br>
<p id = "show_results_button"> </p>
<script>
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<!-- Hello there. This is the only part you need to worry about -->
<!-- DELETE NO SEMICOLONS. -->
<!-- practice_duration is the desired duration in seconds of the practice part of the test.-->
var practice_duration = 10;
<!-- duration is the desired duration in seconds of the each half of the main part of the test.-->
var duration = 10;
<!-- seqlength is the number of images shown during each round of the test; change it as you wish. DO NOT DELETE THE SEMICOLON -->
var seqlength=5;
<!--numimages is the number of distinct images-->
var numimages = 8;
<!--secs_shown is the duration of each image (seconds) and secs_blank is the duration of the gap between images (seconds)-->
var secs_shown = 0.7;
var secs_blank = 0.5;
<!--secs_shown_practice is the duration of each image (seconds) and secs_blank_practice is the duration of the gap between images (seconds)-->
var secs_shown_practice = 0.7;
var secs_blank_practice = 0.5;
<!-- relegation_thresh and promotion_thresh are the threshold scores for going down and up a value of n, respectively. -->
relegation_thresh = 0.85;
promotion_thresh = 0.95;
<!-- The intro_message is the text displayed on the first screen. The font size is the, well, font size. -->
var font_size = 6;
var intro_message = "In this task, some pictures will be presented one after the other in a random order on the screen. Your job, to start with, is to click the button when the current picture on the screen is the same as the picture that occured two previously. For example, if you saw 'cat', 'spoon', 'cat', you would click the button on the second cat. After a certain amount of time, the task may change or stay the same. For example, you may be asked to click when the current picture is the same as the picture that occured one previously, or three previously. If you have any questions, please ask now. When you press 'continue', you will be given a short practice.";
<!-- You can ignore everything after this point -->
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<!-- here we calculate the seqlength for the practice round and number of rounds for the main test-->
var seqlength_practice = Math.round(practice_duration/(2*(secs_blank_practice+secs_shown_practice)));
var num_rounds = Math.round(duration/(seqlength*(secs_shown+secs_blank)));
<!-- set up variables to store the data -->
<!-- Scores is a num_rounds-array of 2-arrays. The first element of each 2-array is n for that round and the second is the score.-->
var scores = [];
for (i=0; i<2*num_rounds; i++){
scores[i] = [0,0];
}
var scores_first = [];
for (i=0; i<num_rounds; i++){
scores_first[i] = [0,0];
}
var scores_second = [];
for (i=0; i<num_rounds; i++){
scores_second[i] = [0,0];
}
<!-- Now we run the real test for the first time. -->
var n=2;
var seq=[];
var responses =[];
var counter = -1;
var image_on = 0;
var round_num = 0;
var practice_round_flip = false;
function round_fun(){
<!-- set up the random sequence and an array to hold the responses -->
counter=-1;
for (i=0; i<seqlength; i++){
responses[i]=0;
}
for (i=0; i<seqlength; i++){
seq[i]=(Math.floor((Math.random() * 10)) % numimages) +1;
}
scores[round_num][0] = n;
<!-- run the round -->
document.getElementById("instruct").innerHTML ="<center><font size = \"12\">Click the 'same' button when the picture shown is the same as the picture that appeared " +n +" previously.</font></center>";
document.getElementById("startbutton").innerHTML = "<center><button type=\"button\" class=\"btn btn-primary btn-lg\"onclick=\"thetest()\">Click here to begin</button></center>";
}
function after_round_1(){
n=2;
document.getElementById("instruct").innerHTML ="<center><font size = \"12\">Well done! Now please fill in the paper questionaire marked 1 in front of you.</font></center>";
document.getElementById("startbutton").innerHTML = "<center><button type=\"button\" class=\"btn btn-primary btn-lg\"onclick = \"round_fun()\">Continue</button></center>";
}
function end_of_test(){
document.getElementById("instruct").innerHTML ="<center><font size = \"12\">Well done! Now please fill in the paper questionaires marked 2 and 3 in front of you. Please do not close the window. Thank you for your time.</font></center>";
<!-- deal with the scores and output -->
for (i=0; i<num_rounds; i++){
scores_first[i][0] = scores[i][0];
scores_first[i][1] = scores[i][1];
scores_second[i][0] = scores[i+num_rounds][0];
scores_second[i][1] = scores[i+num_rounds][1];
}
document.getElementById("show_results_button").innerHTML = "<button class = \"insivbtn\" onclick = \"show_scores()\"><font color = \"white\"> here are the results</font></button>";
}
function show_scores(){
document.getElementById("instruct").innerHTML ="";
document.getElementById("show_results_button").innerHTML = "";
var test_1_string = "";
var test_2_string = "";
var temp_string_scores = "";
for (i=0; i<num_rounds; i++){
test_1_string = test_1_string + "n = ";
test_1_string = test_1_string + scores_first[i][0];
test_1_string = test_1_string + ", score = ";
test_1_string = test_1_string + scores_first[i][1];
test_1_string = test_1_string + "<br>";
test_2_string = test_2_string + "n = ";
test_2_string = test_2_string + scores_second[i][0];
test_2_string = test_2_string + ", score = ";
test_2_string = test_2_string + scores_second[i][1];
test_2_string = test_2_string + "<br>";
}
document.getElementById("test_1_results_title").innerHTML ="First test.";
document.getElementById("test_1_results").innerHTML = test_1_string;
document.getElementById("test_2_results_title").innerHTML ="Second test.";
document.getElementById("test_2_results").innerHTML = test_2_string;
}
<!-- functions for doing parts of the n-back -->
function changeimage() {
if (image_on==seqlength){
document.getElementById("image").innerHTML = "";
document.getElementById("instruct").innerHTML = "";
document.getElementById("yesbutton").innerHTML =" ";
scores[round_num][1] = get_score();
<!-- this is where promotion and relegation happens -->
if (scores[round_num][1]>= promotion_thresh){
n++;
}
if ((scores[round_num][1]<= relegation_thresh) && (n>1)){
n--;
}
round_num++
if (round_num< num_rounds){
round_fun();
}
if (round_num == num_rounds){
after_round_1();
}
if(round_num==2*num_rounds){
end_of_test();
}
if(round_num> num_rounds){
round_fun();
}
}
if (image_on<seqlength){
document.getElementById("image").innerHTML = " ";
setTimeout(new_image, secs_blank*1000);
}
}
function new_image(){
counter++;
document.getElementById("image").innerHTML = "<center><img src =\"" +seq[image_on] +".jpg\" height=\"300\" width=\"300\"></center>";
image_on++;
window.setTimeout(changeimage,secs_shown*1000);
}
function get_score(){
var score = 0;
for (i=0; i<n; i++){
if (responses[i] ==0){
score++;
}
}
for (i=n; i<seqlength; i++){
if (responses[i]==1 && seq[i]==seq[i-n]){
score++;
}
if (responses[i]==0 && seq[i]!=seq[i-n]){
score++;
}
}
score=score/seqlength;
return score;
}
function takeresponse(){
responses[counter] =1;
}
function thetest(){
image_on = 0;
document.getElementById("startbutton").innerHTML =" ";
document.getElementById("yesbutton").innerHTML ="<center><button type=\"button\" class=\"btn btn-success btn-lg\" onclick = \"takeresponse()\">Same</button></center>";
window.setTimeout(changeimage, 2000);
}
function the_main_test(){
document.getElementById("instruct").innerHTML ="<center><font size = \"12\">Well done! Please wait until you are told to continue.</font></center>";
document.getElementById("startbutton").innerHTML = "<center><button type=\"button\" class=\"btn btn-primary btn-lg\"onclick = \"round_fun()\">Continue</button></center>";
}
<!-- modified functions for the practice -->
function practice_round_fun(){
<!-- set up the random sequence and an array to hold the responses -->
counter=-1;
for (i=0; i<seqlength_practice; i++){
seq[i]=(Math.floor((Math.random() * 10)) % numimages) +1;
}
<!-- run the round -->
document.getElementById("instruct").innerHTML ="<center><font size = \"12\">Click the 'same' button when the picture shown is the same as the picture that appeared " +n +" previously.</font></center>";
document.getElementById("startbutton").innerHTML = "<center><button type=\"button\" class=\"btn btn-primary btn-lg\"onclick=\"thetest_practice()\">Click here to begin</button></center>";
}
function thetest_practice(){
image_on = 0;
document.getElementById("startbutton").innerHTML =" ";
document.getElementById("yesbutton").innerHTML ="<center><button type=\"button\" class=\"btn btn-success btn-lg\">Same</button></center>";
window.setTimeout(changeimage_practice, 2000);
}
function changeimage_practice() {
if (image_on==seqlength_practice){
document.getElementById("image").innerHTML = "";
document.getElementById("instruct").innerHTML = "";
document.getElementById("yesbutton").innerHTML =" ";
if (practice_round_flip){
n=2;
the_main_test();
}
else {
n++;
practice_round_flip = true;
practice_round_fun();
}
}
if (image_on<seqlength_practice){
document.getElementById("image").innerHTML = " ";
setTimeout(new_image_practice, secs_blank*1000);
}
}
function new_image_practice(){
counter++;
document.getElementById("image").innerHTML = "<center><img src =\"" +seq[image_on] +".jpg\" height=\"300\" width=\"300\"></center>";
image_on++;
window.setTimeout(changeimage_practice,secs_shown*1000);
}
<!-- display the introductory message and the continue button -->
document.getElementById("instruct").innerHTML = "<font size = \"" +font_size + "\">" + intro_message + "</font>";
document.getElementById("startbutton").innerHTML = "<center><button type = \"button\" class = \"btn btn-primary btn-lg\" onclick = \"the_main_test()\">Continue</buton></center>";
</script>
</body>
</html>