forked from johntango/reactionGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test2.html
47 lines (44 loc) · 1.37 KB
/
test2.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
<html>
<head>
<SCRIPT>
let startTime = 0.0;
let state = 'green';
function Start() {
// start the countDown
state = 'green';
setColor(state);
let delay = Math.round(Math.random()*10000)
setTimeout(goRed, delay);
}
function goRed(){
state = 'red';
startTime = performance.now() // start the timing
setColor(state)
}
function setColor(c){
console.log('setting color to '+c);
document.getElementById('block1').style.backgroundColor = c;
}
function writeMessage(m){
document.getElementById("message").value = m
console.log(m)
}
function Stop() {
let endTime = performance.now();
let time = Math.floor(endTime - startTime);
writeMessage(time);
setColor('white');
state = 'green';
}
</SCRIPT>
</head>
<body>
<p>Click Start - When you see red click Stop".</p>
<button class="button button1" id = "b0" onclick="Start()">Start</button>
<div id = "block1" style.backgroundColor='green'>
<button class="button button2" id = "b1" onclick="Stop()">Stop</button>
</div>
<label id = "label">Reaction in Millesecs: </label><br>
<input id = "message"> </input>
</body>
</html>