-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
82 lines (61 loc) · 1.67 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Random shape</title>
<style type="text/css">
#shape{
width: 200px;
height: 200px;
background: red;
display: none;
}
</style>
</head>
<body>
<h1>Test Your Reactions!</h1>
<p>Your time : <span id="timeTaken"></span></p>
<div id="shape"></div>
<script type="text/javascript">
let start = new Date().getTime();
let shape = document.getElementById("shape");
function getRandomColor(){
let letters = '0123456789ABCDEF'.split('');
let color = '#';
for (let i = 0; i < 6; i++){
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
// Code to display shape
function displayShape(){
let randomSize = Math.floor(Math.random() * 200) + 50;
let randomMargin = Math.floor(Math.random() * 300);
shape.style.display = "block";
shape.style.width = randomSize + "px";
shape.style.height = randomSize + "px";
shape.style.margin = randomMargin + "px";
shape.style.backgroundColor = getRandomColor();
if (Math.random() > 0.5){
shape.style.borderRadius = "50%";
} else{
shape.style.borderRadius = 0;
}
start = new Date().getTime();
}
// Code to display shape after delay
function appearAfterDelay(){
setTimeout(displayShape, Math.random() * 1000);
}
appearAfterDelay();
// Code to hide shape
shape.onclick = function(){
shape.style.display = "none";
let end = new Date().getTime();
let timeTaken = (end - start) / 1000;
document.getElementById("timeTaken").innerHTML = timeTaken + "s";
appearAfterDelay();
}
</script>
</body>
</html>