-
Notifications
You must be signed in to change notification settings - Fork 0
/
02_custom_functions.js
70 lines (56 loc) · 1.79 KB
/
02_custom_functions.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
// Here, you can define all custom functions, you want to use and initialize some variables
/* Variables
*
*
*/
const coin = _.sample(["head", "tail"]); // You can determine global (random) parameters here
// Declare your variables here
/* Helper functions
*
*
*/
/* For generating random participant IDs */
// https://stackoverflow.com/questions/1349404/generate-random-string-characters-in-javascript
// dec2hex :: Integer -> String
const dec2hex = function(dec) {
return ("0" + dec.toString(16)).substr(-2);
};
// generateId :: Integer -> String
const generateID = function(len) {
let arr = new Uint8Array((len || 40) /2);
window.crypto.getRandomValues(arr);
return Array.from(arr, this.dec2hex).join("");
};
// Declare your helper functions here
/* Hooks
*
*
*/
// Error feedback if participants exceeds the time for responding
const time_limit = function(data, next) {
if (typeof window.timeout === 'undefined'){
window.timeout = [];
}
// Add timeouts to the timeoutarray
// Reminds the participant to respond after 5 seconds
window.timeout.push(setTimeout(function(){
$('#reminder').text('Please answer more quickly!');
}, 5000));
next();
};
// compares the chosen answer to the value of `option1`
check_response = function(data, next) {
$('input[name=answer]').on('change', function(e) {
if (e.target.value === data.correct) {
alert('Your answer is correct! Yey!');
} else {
alert('Sorry, this answer is incorrect :( The correct answer was ' + data.correct);
}
next();
})
}
// Declare your hooks here
/* Generators for custom view templates, answer container elements and enable response functions
*
*
*/