Skip to content

Commit cad7e9d

Browse files
Add files via upload
1 parent 22352c6 commit cad7e9d

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

script.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
var start = new Date().getTime();
2+
3+
function getRandomColor() {
4+
5+
var x = Math.floor(Math.random()* 256);
6+
var y = Math.floor(Math.random()* 256);
7+
var z = Math.floor(Math.random()* 256);
8+
9+
var randomColorMaker = "rgb(" + x + "," + y + "," + z + ")";
10+
11+
document.getElementById("shape").style.backgroundColor = randomColorMaker;
12+
}
13+
14+
function makeShapeAppear() {
15+
16+
var top = Math.random()* 400;
17+
18+
var left =Math.random()* 1150;
19+
20+
var width = (Math.random()* 400) + 100;
21+
22+
if(Math.random() < 0.5) {
23+
24+
document.getElementById("shape").style.borderRadius = "50%";
25+
} else {
26+
27+
document.getElementById("shape").style.borderRadius = "0";
28+
}
29+
30+
document.getElementById("shape").style.top = top + "px";
31+
document.getElementById("shape").style.left = left + "px";
32+
document.getElementById("shape").style.width = width + "px";
33+
document.getElementById("shape").style.height = width + "px";
34+
35+
document.getElementById("shape").style.backgroundColor = getRandomColor();
36+
37+
document.getElementById("shape").style.display ="block";
38+
start = new Date().getTime();
39+
}
40+
41+
function Timeout() {
42+
43+
setTimeout(makeShapeAppear, Math.random()* 2000);
44+
45+
}
46+
Timeout();
47+
48+
49+
document.getElementById("shape").onclick = function() {
50+
51+
document.getElementById("shape").style.display = "none";
52+
53+
var end = new Date().getTime();
54+
55+
var timeTaken = (end - start) / 1000 + " sec";
56+
57+
document.getElementById("timeTaken").innerHTML = timeTaken;
58+
59+
var bestTime = 0;
60+
61+
if (timeTaken < bestTime) {
62+
63+
bestTime = timeTaken;
64+
document.getElementById("best").innerHTML = bestTime + " sec";
65+
} else {
66+
67+
document.getElementById("best").innerHTML = timeTaken + " sec";
68+
}
69+
70+
71+
Timeout();
72+
}

0 commit comments

Comments
 (0)