-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreactionTimeTest.html
158 lines (136 loc) · 4.68 KB
/
reactionTimeTest.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
<!DOCTYPE html>
<html>
<head>
<title>reaction time test</title>
<!--<script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
var start = null;
var end = null;
var pressed = null;
var times = [];
var minSeconds = 2;
var maxSeconds = 7;
var addTime = function(time) {
// don't add negative times because that indicates that
// they pushed the button too early
if (time > 0) {
times.push(time/1000);
}
if (times.length > 0) {
$('.output').html('Reflex Delay (Your Time - Optimal Time):<br /><br />' +
times.join(' seconds <br />') + ' seconds');
}
// Reset everything
start = null;
end = null;
pressed = null;
$('.box').removeClass('black');
$('#button').text('Start');
// TODO: enable button
$('#button').removeAttr('disabled');
};
var timer = null;
$('#button').on('mousedown', function () {
if (!start) {
start = new Date().getTime();
$('#button').text('Stop');
var delaySeconds = (Math.random()*(maxSeconds - minSeconds) + minSeconds) * 1000;
console.log('waiting # of seconds: ' + (Math.random()*(maxSeconds - minSeconds) + minSeconds));
timer = window.setTimeout(function () {
$('.box').addClass('black');
end = new Date().getTime();
if (pressed) {
addTime(pressed - end);
}
}, delaySeconds);
} else {
pressed = new Date().getTime();
if (end) {
addTime(pressed - end);
} else {
// disable the button and wait for the timeout
$('#button').attr('disabled', 'disabled');
$('#button').text('Wait for the color to change');
}
}
});
})
</script>
</head>
<body style="overflow:auto; margin:0; padding:0;position:relative" data-gr-c-s-loaded="true">
<style type="text/css" media="screen">
body {
background: aqua;
}
.box {
position: absolute;
right: 0;
top: 0;
width: 50%;
height: 100%;
background-color: white;
border: 2px solid black;
box-sizing: border-box;
}
.black {
background-color: black;
}
.black .btn {
color: white;
}
#button {
width: 100%;
height: 100%;
font-size: 4em;
}
#instructions {
position: absolute;
top: 0;
left: 0;
width: 50%;
height: 30%;
text-align: center;
}
.btn {
.border-radius(0px);
font-weight:bold;
border-color: #B5B5B5;
background-color: none;
background: none;
}
.output {
position: absolute;
bottom: 0;
left: 0;
width: 50%;
height: 50%;
text-align: center;
}
</style>
<div id="instructions">
<h2>Test Your Reaction Time!</h2>
<strong>Instructions</strong>
<br><br>
Click the button to start.
<br>
When the box turns black, click the button again.
</div>
<div id="instructions">
<h2>Test Your Reaction Time!</h2>
<strong>Instructions</strong>
<br><br>
Click the button to start.
<br>
When the box turns black, click the button again.
</div>
<div class="box">
<div id="buttonContainer">
<div class="centerer">
<button class="btn" id="button">Start</button>
</div>
</div>
</div>
</body>
</html>