|
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 () { |
8 | 2 |
|
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 | + } |
14 | 8 |
|
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 + ")"; |
17 | 16 |
|
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() { |
27 | 21 |
|
28 | | - document.getElementById("shape").style.borderRadius = "50%"; |
29 | | - } else { |
| 22 | + var top = Math.random()* 200; |
30 | 23 |
|
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(); |
32 | 45 | } |
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 | | -} |
44 | 46 |
|
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(); |
51 | 53 |
|
52 | 54 |
|
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() { |
67 | 56 |
|
68 | 57 |
|
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 | + } |
75 | 83 | } |
0 commit comments