1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+
4
+ < head >
5
+ < meta charset ="UTF-8 " />
6
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
7
+ < title > 🏴‍☠️ Complete Javascripts Course</ title >
8
+ <!-- Latest compiled and minified CSS -->
9
+ < link rel ="stylesheet " href ="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css "
10
+ integrity ="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u " crossorigin ="anonymous " />
11
+ < style >
12
+ .btn {
13
+ padding : 15px ;
14
+ border : 1px solid # ddd ;
15
+ text-align : center;
16
+ font-size : 1.6em ;
17
+ display : inline-block;
18
+ background-color : red;
19
+ border-radius : 15px ;
20
+ color : white;
21
+ margin : auto;
22
+ cursor : pointer;
23
+ }
24
+
25
+ .container {
26
+ width : 100% ;
27
+ height : 100% ;
28
+ text-align : center;
29
+ margin : auto;
30
+ }
31
+
32
+ .score {
33
+ font-size : 2em ;
34
+ padding : 5px ;
35
+ width : 40% ;
36
+ margin : auto;
37
+ }
38
+ </ style >
39
+ </ head >
40
+
41
+ < body >
42
+ < br />
43
+ < br />
44
+ < div class ="container ">
45
+ < div class ="score "> 0</ div >
46
+ < div class ="startGame btn "> Start Game Here</ div >
47
+ </ div >
48
+
49
+ < script >
50
+ const container = document . querySelector ( ".container" ) ;
51
+ const startGame = document . querySelector ( ".startGame" ) ;
52
+ const scoreArea = document . querySelector ( ".score" ) ;
53
+ let player = {
54
+ score : 0
55
+ } ;
56
+ startGame . addEventListener ( "click" , function ( ) {
57
+ startGame . style . display = "none" ;
58
+ let ranTime = Math . random ( ) * 2000 + 1000 ;
59
+ setTimeout ( makeItem , ranTime ) ;
60
+ } )
61
+
62
+ function makeItem ( ) {
63
+ let boundary = container . getBoundingClientRect ( ) ;
64
+ let div = document . createElement ( "div" ) ;
65
+ div . style . position = "absolute" ;
66
+ div . style . left = Math . random ( ) * boundary . width + "px" ;
67
+ div . style . top = Math . random ( ) * boundary . height + "px" ;
68
+ div . style . width = Math . random ( ) * 10 + 40 + "px" ;
69
+ div . style . height = Math . random ( ) * 10 + 40 + "px" ;
70
+ div . style . borderRadius = "10%" ;
71
+ div . style . cursor = "pointer" ;
72
+ div . style . backgroundColor = "#" + Math . random ( ) . toString ( 16 ) . substr ( - 6 ) ;
73
+ div . style . border = "1px solid black" ;
74
+ div . startTime = Date . now ( ) ;
75
+ div . addEventListener ( "click" , function ( ) {
76
+ let endTime = Date . now ( ) ;
77
+ let diff = ( endTime - div . startTime ) / 1000 ;
78
+ scoreArea . innerHTML = "Clicked in " + diff + "seconds" ;
79
+ //startGame.style.display = "block";
80
+ clearTimeout ( div . timer ) ;
81
+ container . removeChild ( div ) ;
82
+ makeItem ( ) ;
83
+ } )
84
+ div . timer = setTimeout ( function ( ) {
85
+ container . removeChild ( div ) ;
86
+ makeItem ( ) ;
87
+ } , 1000 ) ;
88
+ container . appendChild ( div ) ;
89
+ }
90
+ </ script >
91
+
92
+ < script src ="https://code.jquery.com/jquery-3.2.1.slim.min.js "
93
+ integrity ="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN " crossorigin ="anonymous ">
94
+ </ script >
95
+ < script src ="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js "
96
+ integrity ="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl " crossorigin ="anonymous ">
97
+ </ script >
98
+ < script src ="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js "
99
+ integrity ="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q " crossorigin ="anonymous ">
100
+ </ script >
101
+ </ body >
102
+
103
+ </ html >
0 commit comments