-
Notifications
You must be signed in to change notification settings - Fork 49
/
test7.html
68 lines (66 loc) · 2.33 KB
/
test7.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
<html>
<head>
<link rel="stylesheet" href="mystyles.css">
<SCRIPT>
let startTime = 0.0;
let state = 'green';
const url = 'http://localhost:3000'; // change this to IP address of server
function Start() {
// start the countDown
state = 'green';
setColor(state);
let delay = Math.round(Math.random()*10000);
console.log("delay="+delay)
setTimeout(goRed, delay);
}
function goRed(){
state = 'red';
startTime = performance.now() // start the timing
document.getElementById('block1').style.backgroundColor = 'red'
}
function setColor(c){
console.log('setting color to '+c);
document.getElementById('block1').style.backgroundColor = c;
}
function writeMessage(m){
document.getElementById("message").value = m
// send position data to Server in url
fetch(url + '/set?x=' + m)
.then(response => response.json())
.then(data => inject(data));
console.log(m)
}
function inject(data){
document.getElementById("label").innerHTML = "Fastest Reaction Recorded:" + data;
}
function getFastest(){
fetch(url + '/fastest')
.then(response => response.json())
.then(data => inject(data));
}
function checkForDeath(time){
if(time > 5000){
document.getElementById("label").innerHTML = "NEAR DEATH SEEK MEDICAL HELP:";
}
}
function Stop() {
if(state == 'green') return;
let endTime = performance.now();
let time = Math.floor(endTime - startTime);
writeMessage(time);
checkForDeath(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>
<input id = "message"> </input>
</body>
</html>