-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
190 lines (176 loc) · 5.3 KB
/
main.js
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
/*
This task is modeled after the 5-Trial Delay Discounting Task described in the 2014 paper
"A 5-trial adjusting delay discounting task: Accurate discount rates in less than 60 seconds"
by Mikhail Koffarnus and Warren Bickel.
*/
//TODO:
//get to work on qualtrics
let initialD = 16;
//this is the initial delay which is set to 16 as per Koffarnus and Bickel's papers
//this corresponds to the key 16 on the map below
const dMap = new Map([
[1, "1 hour"],
[2, "2 hours"],
[3, "3 hours"],
[4, "4 hours"],
[5, "6 hours"],
[6, "9 hours"],
[7, "12 hours"],
[8, "1 day",],
[9, "1 and a half days"],
[10, "2 days"],
[11, "3 days"],
[12, "4 days"],
[13, "1 week"],
[14, "1 and a half weeks"],
[15, "2 weeks"],
[16, "3 weeks"], //always the first option
[17, "1 month"],
[18, "2 months"],
[19, "3 months"],
[20, "4 months"],
[21, "6 months"],
[22, "8 months"],
[23, "1 years"],
[24, "2 years"],
[25, "3 years"],
[26, "4 years"],
[27, "5 years"],
[28, "8 years"],
[29, "12 years"],
[30, "18 years"],
[31, "25 years"],
]);
const stim = '<div style="font-size:20px;font-weight:bold;">Which would you rather get?</div>';
var timeline = [];
//todo: change buttons
var trial1 = {
type: jsPsychHtmlButtonResponse,
stimulus: stim,
choices: ['$1000 in ' + dMap.get(initialD) +' and $0 now', '$500 now and $0 in '+ dMap.get(initialD) + ''], //starts at 16
button_html: '<button class="button">%choice%</button>',
response_ends_trial: true,
on_finish: function(data){
data.index = [initialD, dMap.get(initialD)];
console.log();
if (data.response == 0) { //record the response for the current trial
data.delay = true;
}
else {
data.delay = false;
}
}
}
var trial2 = {
type: jsPsychHtmlButtonResponse,
stimulus: stim,
choices: function() {
var last_trial_choice = jsPsych.data.get().last(1).values()[0].delay; //either true or false
if (last_trial_choice) { //if last trial was true
initialD = initialD + 8;
return ['$1000 in ' + dMap.get(initialD) + ' and $0 now', '$500 now and $0 in '+ dMap.get(initialD) + '']
}
else {
initialD = initialD - 8;
return ['$1000 in ' + dMap.get(initialD) + ' and $0 now', '$500 now and $0 in '+ dMap.get(initialD) + '']
}
},
button_html: '<button class="button">%choice%</button>',
response_ends_trial: true,
on_finish: function(data){
data.index = [initialD, dMap.get(initialD)];
console.log();
if (data.response == 0) {
data.delay = true;
}
else {
data.delay = false;
}
}
}
var trial3 = {
type: jsPsychHtmlButtonResponse,
stimulus: stim,
choices: function() {
var last_trial_choice = jsPsych.data.get().last(1).values()[0].delay;
if (last_trial_choice) {
initialD = initialD + 4; //divides by 2 each trial (8 then 4 then 2 then 1)
return ['$1000 in ' + dMap.get(initialD) + ' and $0 now', '$500 now and $0 in '+ dMap.get(initialD) + '']
}
else {
initialD = initialD - 4;
return ['$1000 in ' + dMap.get(initialD) + ' and $0 now', '$500 now and $0 in '+ dMap.get(initialD) + '']
}
},
button_html: '<button class="button">%choice%</button>',
response_ends_trial: true,
on_finish: function(data){
data.index = [initialD, dMap.get(initialD)];
console.log();
if (data.response == 0) {
data.delay = true;
}
else {
data.delay = false;
}
}
}
var trial4 = {
type: jsPsychHtmlButtonResponse,
stimulus: stim,
choices: function() {
var last_trial_choice = jsPsych.data.get().last(1).values()[0].delay;
if (last_trial_choice) {
initialD = initialD + 2;
return ['$1000 in ' + dMap.get(initialD) + ' and $0 now', '$500 now and $0 in '+ dMap.get(initialD) + '']
}
else {
initialD = initialD - 2;
return ['$1000 in ' + dMap.get(initialD) + ' and $0 now', '$500 now and $0 in '+ dMap.get(initialD) + '']
}
},
button_html: '<button class="button">%choice%</button>',
response_ends_trial: true,
on_finish: function(data){
data.index = [initialD, dMap.get(initialD)];
console.log();
if (data.response == 0) {
data.delay = true;
}
else {
data.delay = false;
}
}
}
var trial5 = {
type: jsPsychHtmlButtonResponse,
stimulus: stim,
choices: function() {
var last_trial_choice = jsPsych.data.get().last(1).values()[0].delay;
if (last_trial_choice) {
initialD = initialD + 1;
return ['$1000 in ' + dMap.get(initialD) + ' and $0 now', '$500 now and $0 in '+ dMap.get(initialD) + '']
}
else {
initialD = initialD - 1;
return ['$1000 in ' + dMap.get(initialD) + ' and $0 now', '$500 now and $0 in '+ dMap.get(initialD) + '']
}
},
button_html: '<button class="button">%choice%</button>',
response_ends_trial: true,
on_finish: function(data){
data.index = [initialD, dMap.get(initialD)];
console.log();
if (data.response == 0) {
data.delay = true;
}
else {
data.delay = false;
}
}
}
timeline.push(trial1);
timeline.push(trial2);
timeline.push(trial3);
timeline.push(trial4);
timeline.push(trial5);