forked from longouyang/even-odd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathff_check.js
More file actions
86 lines (56 loc) · 2.95 KB
/
ff_check.js
File metadata and controls
86 lines (56 loc) · 2.95 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
// ## High-level overview
// This check-in is to equate the short and long delay groups in "propensity to come back after a three day delay." The only requirement is to hit the start button.
// ## Prep data
var allData = {
fingerprintData: fingerprint
};
showSlide("codescreen");
// ## Code validation
var code = "";
$("form").submit( function (){
$("#validated").text("")
$("#validated").attr("style", "color:red");
code = $("#getcode")[0].elements["code"].value; //global scope, try to fix later
// screen for invalid format
if (!(code.length == 32 &&
code.slice(0,4) == "0176" &&
code.slice(-4) == "0198" &&
!isNaN(code))) {
$("#validated").text("Invalid code. Please enter a valid code.");
return;
}
// convert to date
var startDate = codeToDate(code.slice(4,16))
var endDate = codeToDate(code.slice(16,28))
var curDate = new Date();
// screen for invalid dates
if (!startDate || !endDate || startDate > endDate){
$("#validated").text("Invalid code. Please enter a valid code.");
return;
}
// check time
// too soon
if (startDate > curDate){
$("#validated").text("This code is only valid for use between " + dateToString(startDate) + " and " + dateToString(endDate) + ". Please come back soon!");
// too late
} else if (endDate < curDate) {
$("#validated").text("This code expired on " + dateToString(endDate));
// just right!
} else {
if (turk.previewMode) {
$("#validated").text("This code is valid but cannot submit while in preview mode.");
$("#validated").attr("style", "color:green");
return;
}
allData.entrycode = code;
showSlide("instructions");
}
})
// ## Finish slide
function end() {
// Show the finish slide.
showSlide("finished");
allData.submitTime = new Date().toString()
// Wait 1.5 seconds and then submit the whole experiment object to Mechanical Turk (mmturkey filters out the functions so we know we're just submitting properties [i.e. data])
setTimeout(function() { turk.submit(allData) }, 1500);
}