Skip to content

Commit 4eeda53

Browse files
committed
store bst time
1 parent 09ba91b commit 4eeda53

File tree

1 file changed

+72
-71
lines changed

1 file changed

+72
-71
lines changed

script.js

Lines changed: 72 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,73 @@
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-
1+
var bestTime = 0;
2+
var start = new Date().getTime();
3+
4+
function getRandomColor() {
5+
6+
var x = Math.floor(Math.random()* 256);
7+
var y = Math.floor(Math.random()* 256);
8+
var z = Math.floor(Math.random()* 256);
9+
10+
var randomColorMaker = "rgb(" + x + "," + y + "," + z + ")";
11+
12+
document.getElementById("shape").style.backgroundColor = randomColorMaker;
13+
}
14+
15+
function makeShapeAppear() {
16+
17+
var top = Math.random()* 400;
18+
19+
var left =Math.random()* 1150;
20+
21+
var width = (Math.random()* 400) + 100;
22+
23+
if(Math.random() < 0.5) {
24+
25+
document.getElementById("shape").style.borderRadius = "50%";
26+
} else {
4827

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-
}
28+
document.getElementById("shape").style.borderRadius = "0";
29+
}
30+
31+
document.getElementById("shape").style.top = top + "px";
32+
document.getElementById("shape").style.left = left + "px";
33+
document.getElementById("shape").style.width = width + "px";
34+
document.getElementById("shape").style.height = width + "px";
35+
36+
document.getElementById("shape").style.backgroundColor = getRandomColor();
37+
38+
document.getElementById("shape").style.display ="block";
39+
start = new Date().getTime();
40+
}
41+
42+
function Timeout() {
43+
44+
setTimeout(makeShapeAppear, Math.random()* 2000);
45+
46+
}
47+
Timeout();
48+
49+
50+
document.getElementById("shape").onclick = function() {
51+
52+
53+
document.getElementById("shape").style.display = "none";
54+
55+
var end = new Date().getTime();
56+
57+
var timeTaken = (end - start) / 1000 + " sec";
58+
59+
document.getElementById("timeTaken").innerHTML = timeTaken;
60+
61+
62+
63+
if (timeTaken < bestTime || bestTime == 0) {
64+
bestTime = timeTaken;
65+
document.getElementById("best").innerHTML = bestTime + "s"
66+
} else {
67+
68+
document.getElementById("best").innerHTML = timeTaken + " sec";
69+
}
70+
71+
72+
Timeout();
73+
}

0 commit comments

Comments
 (0)