Skip to content

Commit d4e7893

Browse files
committed
add exit button, redirections
1 parent 93bfad5 commit d4e7893

3 files changed

Lines changed: 81 additions & 64 deletions

File tree

index.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
Your Best Time: <span id="best" style="color: blue;"></span>
2121

2222
</p>
23-
<div><button id="rules" style="text-align: center; width: 150px; margin-left: 800px; border-radius: 10px;">Tip</button></div>
23+
<div>
24+
<button id="rules">Tip</button>
25+
<a href="/intro.html"><button id="exit">Exit</button></a>
26+
</div>
2427

2528
<div id="shape"></div>
2629
<canvas id="myCanvas" width="1500" height="300">

script.js

Lines changed: 71 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,83 @@
1-
var bestTime = 10;
2-
var start = new Date().getTime();
3-
document.getElementById("rules").onclick = function () {
4-
alert("Try to click the shapes as soon as possible to increase your score");
5-
}
6-
7-
function getRandomColor() {
1+
window.onload = function () {
82

9-
var x = Math.floor(Math.random()* 256);
10-
var y = Math.floor(Math.random()* 256);
11-
var z = Math.floor(Math.random()* 256);
12-
13-
var randomColorMaker = "rgb(" + x + "," + y + "," + z + ")";
3+
var bestTime = 10;
4+
var start = new Date().getTime();
5+
document.getElementById("rules").onclick = function () {
6+
alert("Try to click the shapes as soon as possible to increase your score");
7+
}
148

15-
document.getElementById("shape").style.backgroundColor = randomColorMaker;
16-
}
9+
function getRandomColor() {
10+
11+
var x = Math.floor(Math.random()* 256);
12+
var y = Math.floor(Math.random()* 256);
13+
var z = Math.floor(Math.random()* 256);
14+
15+
var randomColorMaker = "rgb(" + x + "," + y + "," + z + ")";
1716

18-
function makeShapeAppear() {
19-
20-
var top = Math.random()* 200;
21-
22-
var left =Math.random()* 1150;
23-
24-
var width = (Math.random()* 400) + 100;
25-
26-
if(Math.random() > 0.5) {
17+
document.getElementById("shape").style.backgroundColor = randomColorMaker;
18+
}
19+
20+
function makeShapeAppear() {
2721

28-
document.getElementById("shape").style.borderRadius = "50%";
29-
} else {
22+
var top = Math.random()* 200;
3023

31-
document.getElementById("shape").style.borderRadius = "0";
24+
var left =Math.random()* 1150;
25+
26+
var width = (Math.random()* 400) + 100;
27+
28+
if(Math.random() > 0.5) {
29+
30+
document.getElementById("shape").style.borderRadius = "50%";
31+
} else {
32+
33+
document.getElementById("shape").style.borderRadius = "0";
34+
}
35+
36+
document.getElementById("shape").style.top = top + "px";
37+
document.getElementById("shape").style.left = left + "px";
38+
document.getElementById("shape").style.width = width + "px";
39+
document.getElementById("shape").style.height = width + "px";
40+
41+
document.getElementById("shape").style.backgroundColor = getRandomColor();
42+
43+
document.getElementById("shape").style.display ="block";
44+
start = new Date().getTime();
3245
}
33-
34-
document.getElementById("shape").style.top = top + "px";
35-
document.getElementById("shape").style.left = left + "px";
36-
document.getElementById("shape").style.width = width + "px";
37-
document.getElementById("shape").style.height = width + "px";
38-
39-
document.getElementById("shape").style.backgroundColor = getRandomColor();
40-
41-
document.getElementById("shape").style.display ="block";
42-
start = new Date().getTime();
43-
}
4446

45-
function Timeout() {
46-
47-
setTimeout(makeShapeAppear, Math.random()* 2000);
48-
49-
}
50-
Timeout();
47+
function Timeout() {
48+
49+
setTimeout(makeShapeAppear, Math.random()* 2000);
50+
51+
}
52+
Timeout();
5153

5254

53-
document.getElementById("shape").onclick = function() {
54-
55-
56-
document.getElementById("shape").style.display = "none";
57-
58-
var end = new Date().getTime();
59-
60-
var timeTaken = (end - start) / 1000;
61-
62-
document.getElementById("timeTaken").innerHTML = timeTaken + " sec";
63-
64-
if(timeTaken < bestTime) {
65-
bestTime = timeTaken;
66-
document.getElementById("best").innerHTML = bestTime + " sec";
55+
document.getElementById("shape").onclick = function() {
6756

6857

69-
}
70-
71-
72-
73-
74-
Timeout();
58+
document.getElementById("shape").style.display = "none";
59+
60+
var end = new Date().getTime();
61+
62+
var timeTaken = (end - start) / 1000;
63+
64+
document.getElementById("timeTaken").innerHTML = timeTaken + " sec";
65+
66+
if(timeTaken < bestTime) {
67+
bestTime = timeTaken;
68+
document.getElementById("best").innerHTML = bestTime + " sec";
69+
70+
71+
}
72+
73+
74+
75+
76+
Timeout();
77+
}
78+
// exit function
79+
exit.onclick = function(e) {
80+
score = bestTime*1000;
81+
alert("Great, You Best Score till now is: " + score);
82+
}
7583
}

style.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,9 @@ position: relative;
1111
font-weight: bold;
1212
color:red;
1313
}
14+
button {
15+
text-align: center;
16+
width: 150px;
17+
margin-left: 800px;
18+
border-radius: 10px;
19+
}

0 commit comments

Comments
 (0)