-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex-affix-kid.html
426 lines (381 loc) · 13.9 KB
/
index-affix-kid.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
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
<!DOCTYPE html>
<html>
<head>
<title>My experiment</title>
<!-- <script type="text/javascript" src="conditions.js"></script> -->
<script src="https://unpkg.com/[email protected]"></script>
<script src="https://unpkg.com/@jspsych/[email protected]"></script>
<script src="https://unpkg.com/@jspsych/[email protected]"></script>
<script src="https://unpkg.com/@jspsych/[email protected]"></script>
<script src="https://unpkg.com/@jspsych/[email protected]"></script>
<script src="https://unpkg.com/@jspsych/[email protected]"></script>
<script src="https://unpkg.com/@jspsych/[email protected]"></script>
<script src="https://unpkg.com/@jspsych/[email protected]"></script>
<script src="https://unpkg.com/@jspsych/[email protected]"></script>
<script src="https://nyc3.digitaloceanspaces.com/experiments.childlanglab/childlanglabClient.js"></script>
<script src="params_affix.js"></script>
<link
href="https://unpkg.com/[email protected]/css/jspsych.css"
rel="stylesheet"
type="text/css"
/>
<style>
/* Prevent color change on hover */
/* .jspsych-btn:hover {
background-color:#f4f5f7; /* Maintain the same background color on hover */
</style>
</head>
<!-- Use the task.js file in this folder -->
<script>
// childlanglabClient.sayHello()
// childlanglabClient.sendData( [{"this":"that"}])
// initialize jsPsych
var jsPsych = initJsPsych({
default_iti: 0,
show_progress_bar: true,
on_start: function(){
},
on_finish: function () {
// let data = jsPsych.data.get().json();
// jsPsych.data.displayData();
//window.location.replace("https://app.prolific.com/submissions/complete?cc=C1YFAOAM")
},
});
// define the arrangment of choices so we can get the correct value
var choice_position = ['r', 'n']
// define the counter to count correct trials
var count_correct = 0
var count_total = 0
var count_level = 0
// function to update correct counters
function update_counters(data){
// save what choice was
data.choice = choice_position[data.response];
// increment the count total (we've gone up one total trial)
count_total++
// in increment the correct counter if we are correct
if(choice_position[data.response] === data.word_type){
count_correct++
data.is_correct = true;
} else {
data.is_correct = false;
}
// see what this looks like in the console
console.log("updating counts", count_correct, count_total)
console.log("data object", data)
};
// randomly assign participant to one of 3 lists
var lists = [
{name: "list1", list: LIST1},
{name: "list2", list: LIST2},
{name: "list3", list: LIST3}
]
var random_list = jsPsych.randomization.sampleWithReplacement(lists, 1)[0]
jsPsych.data.addProperties({list: random_list.name});
// function to get the stimuli list for each block
function get_stimuli_list(list = [], block = ""){
let stimuli_list = list.filter(trial => trial.block === block)
return stimuli_list
}
// function to generate a random ISI in between each feedback trial
// feedback trials are 300ms long (showing correct fish); random isi adds
// an additional X ms of blank screen in between hearing the sound
// either 100, 150, 200, 250, 300 ms (equivalent to 400, 450, 500, 550, or 600)
var random_isi = function(){
var random_ms = jsPsych.randomization.sampleWithReplacement([300, 350, 400, 450, 500, 550, 600], 1)[0]
return random_ms
}
var sendData = {
type: jsPsychCallFunction,
async: true,
func: function (done) {
let data = jsPsych.data.get().json();
childlanglabClient.sendData(data);
done("Sent data object to childlanglab-api")
},
};
/* preload images */
var preload = {
type: jsPsychPreload,
images: PRELOAD.images,
continue_after_error: false,
show_detailed_errors: true,
sounds: PRELOAD.sounds,
};
// function check_consent (elem) {
// if (document.getElementById('consent_checkbox').checked) {
// return true;
// }
// else {
// alert("If you wish to participate, you must check the box next to the statement 'I agree to participate in this study.'");
// return false;
// }
// return false;
// };
// var consent = {
// type: jsPsychExternalHtml,
// url: "consent.html",
// cont_btn: "start",
// check_fn: check_consent
// };
/* define welcome message trial */
var welcome = {
type: jsPsychHtmlButtonResponse,
stimulus: "Welcome to the experiment. Press next when you are ready to begin.",
choices: ["Next"]
};
var start = {
type: jsPsychHtmlButtonResponse,
stimulus: "Ready to start? Press next when you are ready.",
choices: ["Next"]
};
var finish = {
type: jsPsychHtmlKeyboardResponse,
stimulus: "Sending data to our secure database...",
trial_duration: 2000,
response_ends_trial: false
};
var thanks = {
type: jsPsychHtmlButtonResponse,
stimulus: "Thanks for participating! Press finish to complete the study",
choices: ["Finish"]
};
/* define instructions trial */
var instructions = {
type: jsPsychInstructions,
pages: [
`<div>
<p>In this experiment, there are two kinds of talking fish</p>
<div style='float: left;'><img src='img/fish-real.png'></div>
<div style='float: right;'><img src='img/fish-silly.png'></img></div>
</div>
`,
`<p>Gray fish always say <strong>real words</strong></p>
<div><img src='img/fish-real.png'></img></div><br>
`,
`<p>Rainbow fish always say <strong>silly words</strong></p>
<div><img src='img/fish-silly.png'></img></div><br>
`,
`<p>There are also two hungry penguins</p>
<div style='float: left;'><img src='img/penguin-real.png' style="width: 200px"></div>
<div style='float: right;'><img src='img/penguin-silly.png' style="width: 200px"></img></div><br>
`,
`<p>One penguin only eats fish who say <strong>real words</strong></p>
<div><img src='img/penguin-real.png' style="width: 200px"></img></div><br>
`,
`<p>The other penguin only eats fish who say <strong>silly words</strong></p>
<div><img src='img/penguin-silly.png' style="width: 200px"></img></div><br>
`,
`<p>We will hide the color of the fish. </p>
<div><img src="img/fish-blank.png"></div>
</p>Your job is to guess which penguin will eat the fish based on the word it says.</p>
<div style='width: 400px; margin:auto;'>
<div style='float: left;'><img src='img/penguin-real.png' style="width: 200px"></img>
<p class='small'>Only <strong>real words</strong></p></div>
<div style='float: right;'><img src='img/penguin-silly.png' style="width: 200px"></img>
<p class='small'>Only <strong>silly words</strong></p></div>
</div>`,
`<p>Keep in mind: the gray fish is very casual. This means that it will sometimes pronounce words in a more casual style (e.g. "cookin'" instead of "cooking").</p><p> You should consider these casual pronunciations <strong>real words</strong></p>`
],
show_clickable_nav: true
};
// define break trials
function get_break_trial(level){
var takeBreak = {
type: jsPsychHtmlButtonResponse,
stimulus: function() {
return `<p> Great job you completed Level ${count_level} of 5!</p><img src="img/level${count_level}.png" style="width: 600px"><p>You got ${count_correct} of ${count_total} fish! You earned snowman #${count_level}! </p>`
} ,
choices: ["Next"],
prompt: "<p>Press next when you are ready to continue</p>"
}
return takeBreak;
};
/*define prime and target trials */
var prime = {
type: jsPsychImageButtonResponse,
stimulus: "img/fish-blank-resize.png",
choices: ["img/penguin-real.png", "img/penguin-silly.png"],
prompt: function(){
return `<p>Which penguin will eat this fish?</p><p>Level ${count_level}, Score ${count_correct}</p>`
},
button_html:
'<button class="jspsych-btn"><img src="%choice%" style="width: 200px"/></button>',
render_on_canvas: true,
on_start: function () {
// console.log("prime: " + jsPsych.timelineVariable("prime_sound"));
// play audio at the start of the trial
audio = new Audio();
audio.src = jsPsych.timelineVariable("prime_sound");
audio.play();
},
on_finish: function(data){
update_counters(data);
},
data: {
is_target: false,
word: jsPsych.timelineVariable("prime"),
sound: jsPsych.timelineVariable("prime_sound"),
which_correct: jsPsych.timelineVariable("prime_correct"),
block: jsPsych.timelineVariable("block"),
item: jsPsych.timelineVariable("item"),
type: jsPsych.timelineVariable("type"),
c_f_type: jsPsych.timelineVariable("c_f_type"),
word_type: jsPsych.timelineVariable("prime_type"),
}
};
var target = {
type: jsPsychImageButtonResponse,
stimulus: "img/fish-blank-resize.png",
choices: ["img/penguin-real.png", "img/penguin-silly.png"],
prompt: function(){
return `<p>Which penguin will eat this fish?</p><p>Level ${count_level}, Score ${count_correct}</p>`
},
button_html:
'<button class="jspsych-btn"><img src="%choice%" style="width: 200px"/></button>',
render_on_canvas: true,
on_start: function () {
// console.log("target: " + jsPsych.timelineVariable("target_sound"));
// play audio at the start of the trial
audio = new Audio();
audio.src = jsPsych.timelineVariable("target_sound");
audio.play();
},
on_finish: function(data){
update_counters(data);
},
data: {
is_target: true,
word: jsPsych.timelineVariable("target"),
sound: jsPsych.timelineVariable("target_sound"),
which_correct: jsPsych.timelineVariable("target_correct"),
block: jsPsych.timelineVariable("block"),
item: jsPsych.timelineVariable("item"),
type: jsPsych.timelineVariable("type"),
c_f_type: jsPsych.timelineVariable("c_f_type"),
word_type: jsPsych.timelineVariable("target_type"),
}
};
/* define prime and target feedback trials */
var prime_feedback = {
type: jsPsychImageButtonResponse,
stimulus: jsPsych.timelineVariable("prime_correct"),
choices: ["img/penguin-real.png", "img/penguin-silly.png"],
prompt: function(){
return `<p>Which penguin will eat this fish?</p><p>Level ${count_level}, Score ${count_correct}</p>`
},
button_html: function(){
// Get the data of the last trial
var realSize = "200px";
var sillySize = "200px"
var lastTrialData = jsPsych.data.getLastTrialData();
// Access values from the last trial
var isCorrect = lastTrialData.select('is_correct').values[0]; // Adjust "response" to the appropriate key in your data
var whichCorrect = lastTrialData.select('which_correct').values[0];
console.log(isCorrect, whichCorrect);
if(isCorrect & whichCorrect == "img/fish-real.png"){
realSize = "250px"
} else if(isCorrect & whichCorrect == "img/fish-silly.png"){
sillySize = "250px"
}
return [`<button class="jspsych-btn disabled"><img src="%choice%" style="width: ${realSize}"/></button>`, `<button class="jspsych-btn disabled"><img src="%choice%" style="width: ${sillySize}"/></button>`]
},
render_on_canvas: true,
trial_duration: 300,
response_ends_trial: false,
// post_trial_gap: random_isi,
save_trial_parameters: {
stimulus: true,
trial_duration: true,
}
};
var target_feedback = {
type: jsPsychImageButtonResponse,
stimulus: jsPsych.timelineVariable("target_correct"),
choices: ["img/penguin-real.png", "img/penguin-silly.png"],
prompt: function(){
return `<p>Which penguin will eat this fish?</p><p>Level ${count_level}, Score ${count_correct}</p>`
},
button_html: function(){
// Get the data of the last trial
var realSize = "200px";
var sillySize = "200px"
var lastTrialData = jsPsych.data.getLastTrialData();
// Access values from the last trial
var isCorrect = lastTrialData.select('is_correct').values[0]; // Adjust "response" to the appropriate key in your data
var whichCorrect = lastTrialData.select('which_correct').values[0];
console.log(isCorrect, whichCorrect);
if(isCorrect & whichCorrect == "img/fish-real.png"){
realSize = "250px"
} else if(isCorrect & whichCorrect == "img/fish-silly.png"){
sillySize = "250px"
}
return [`<button class="jspsych-btn disabled"><img src="%choice%" style="width: ${realSize}"/></button>`, `<button class="jspsych-btn disabled"><img src="%choice%" style="width: ${sillySize}"/></button>`]
},
render_on_canvas: true,
trial_duration: 300,
response_ends_trial: false,
// post_trial_gap: random_isi,
save_trial_parameters: {
stimulus: true,
trial_duration: true,
}
};
var isi = {
type: jsPsychImageButtonResponse,
stimulus: "img/fish-placeholder.png",
choices: ["img/penguin-real.png", "img/penguin-silly.png"],
prompt: function(){
return `<p>Which penguin will eat this fish?</p><p>Level ${count_level}, Score ${count_correct}</p>`
},
button_html:
'<button class="jspsych-btn disabled"><img src="%choice%" style="width: 200px"/></button>',
render_on_canvas: true,
trial_duration: random_isi,
response_ends_trial: false,
save_trial_parameters: {
stimulus: true,
trial_duration: true,
}
};
/* define blocks */
function get_block(which_block = ""){
var block = {
timeline: [prime, prime_feedback, isi, target, target_feedback, isi],
timeline_variables: get_stimuli_list(random_list.list, which_block),
repetitions: 1,
randomize_order: true,
on_timeline_start: function(){
// at the start of the timeline, reset our correct counter to zero.
count_level++
count_correct = 0;
count_total = 0;
},
}
return block;
};
/* create timeline */
var timeline = [
welcome,
preload,
instructions,
start,
get_block("practice"),
get_break_trial(0),
get_block("a"),
get_break_trial(1),
get_block("b"),
get_break_trial(2),
get_block("c"),
get_break_trial(3),
get_block("d"),
get_break_trial(4),
sendData,
finish,
thanks
];
/* start the experiment */
jsPsych.run(timeline);
</script>
<body></body>
</html>