-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGetting the opening time.js
42 lines (37 loc) · 1.1 KB
/
Getting the opening time.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
Qualtrics.SurveyEngine.addOnReady(function () {
rows = this.getChoiceContainer().querySelectorAll("tr.ChoiceRow");
summer = (sum, val) => sum + val;
input_boxes = [];
for (i = 0; i < rows.length; i++) {
bx = rows[i].querySelectorAll("input");
for (j = 0; j < bx.length; j++) {
input_boxes.push(bx[j]);
}
}
input_boxes.forEach((item) => item.addEventListener("input", get_hours));
function get_hours() {
open_for = [];
for (i = 0; i < rows.length; i++) {
tot = [];
for (j = 0; j < 2; j++) {
m = i * 2 + j;
t = input_boxes[m].value;
if(t.includes(":")){
t = t.split(":");
timing = Number(t[0]) * 60 + Number(t[1]);
} else{
timing = Number(t) * 60;
}
tot.push(timing);
}
open_for.push(tot[1] - tot[0]);
}
open_hours = (open_for.reduce(summer) / 60).floor();
open_mins = open_for.reduce(summer) - (open_hours * 60) ;
open_text = open_hours + " Hours";
if(open_mins){
open_text += " and " + open_mins + " minutes";
}
Qualtrics.SurveyEngine.setEmbeddedData("hours_open", open_text);
}
});