File tree Expand file tree Collapse file tree 1 file changed +58
-0
lines changed Expand file tree Collapse file tree 1 file changed +58
-0
lines changed Original file line number Diff line number Diff line change 1+ var timer = 60 ;
2+ var score = 0 ;
3+ var hitrn ;
4+
5+
6+ function increaseScore ( ) {
7+ score += 10 ;
8+ document . querySelector ( "#scoreVal" ) . textContent = score ;
9+ }
10+
11+ function getNewHit ( ) {
12+ hitrn = Math . floor ( Math . random ( ) * 10 ) ;
13+ document . querySelector ( "#hitNum" ) . textContent = hitrn ;
14+ }
15+
16+
17+
18+ function makeBubble ( ) {
19+ var clutter = "" ;
20+ for ( var i = 1 ; i <= 180 ; i ++ ) {
21+ var rn = Math . floor ( Math . random ( ) * 10 )
22+ clutter += `<div class="bubble">${ rn } </div>` ;
23+ }
24+ document . querySelector ( "#pbtm" ) . innerHTML = clutter ;
25+ }
26+
27+
28+
29+ function runTimer ( ) {
30+ var timerInt = setInterval ( function ( ) {
31+ if ( timer > 0 ) {
32+ timer -- ;
33+ document . querySelector ( "#timerInterval" ) . textContent = timer ;
34+ }
35+ else {
36+ clearInterval ( timerInt ) ;
37+ document . querySelector ( "#pbtm" ) . innerHTML = `<h1>Game Over <br>
38+ Your Score is = ${ score } </h1>` ;
39+ document . querySelector ( "#hitNum" ) . textContent = 0 ;
40+ document . querySelector ( "#scoreVal" ) . textContent = 0 ;
41+ }
42+ } , 1000 ) ;
43+ }
44+
45+
46+ document . querySelector ( "#pbtm" )
47+ . addEventListener ( "click" , function ( dets ) {
48+ var clickednum = Number ( dets . target . textContent ) ;
49+ if ( clickednum == hitrn ) {
50+ increaseScore ( ) ;
51+ makeBubble ( ) ;
52+ getNewHit ( ) ;
53+ }
54+ } ) ;
55+
56+ runTimer ( ) ;
57+ makeBubble ( ) ;
58+ getNewHit ( ) ;
You can’t perform that action at this time.
0 commit comments