8
8
< link rel ="stylesheet " href ="">
9
9
< style >
10
10
button {
11
- height : 20em ; width : 20em ; border-radius : 2em ; margin-top : 2em ; background-color : palegreen;
12
- }
11
+ height : 20em ; width : 20em ; border-radius : 2em ; margin-top : 2em ; background-color : palegreen;}
12
+
13
13
button : focus {
14
- outline : 0 ;
15
- }
14
+ outline : 0 ;}
16
15
div {
17
- margin : 10em ; text-align : center;
18
- }
16
+ margin : 5em ; text-align : center;}
19
17
h1 {
20
18
margin : 0 2em ;
21
- white-space : nowrap;
22
- }
19
+ white-space : nowrap;}
23
20
h2 {
24
21
margin : .5em 3em ;
25
- white-space : nowrap;
26
- }
22
+ white-space : nowrap;}
27
23
</ style >
28
24
</ head >
29
25
< body >
30
26
< div >
31
- < h1 id ="result "> Nothing yet</ h1 >
32
- < button onclick ="handleClick() "> Click</ button >
27
+ < h1 id ="result "> Click Any Of The Buttons And Try Your Luck!</ h1 >
28
+ < div id ="buttons ">
29
+ < button onclick ="handleClick() "> Click</ button >
30
+ < button onclick ="handleClick() "> Click</ button >
31
+ < button onclick ="handleClick() "> Click</ button >
32
+ < button onclick ="handleClick() "> Click</ button >
33
+ < button onclick ="handleClick() "> Click</ button >
34
+ < button onclick ="handleClick() "> Click</ button >
35
+ </ div >
33
36
< h2 > Counter: < span id ="count "> 0</ span > </ h2 >
34
37
< h2 > Record: < span id ="record "> 0</ span > </ h2 >
38
+ < button hidden onclick ="reset() " id ="reset "> Try Again </ button >
35
39
</ div >
36
40
< script async defer >
37
41
let counter = 0 ;
38
42
let record = 0 ;
39
43
let state = false ;
40
-
41
44
function handleClick ( ) {
42
45
if ( Math . floor ( Math . random ( ) * 6 ) == 0 ) {
46
+ document . getElementById ( "result" ) . innerText = "Bang! You survived " + counter + " click" ;
43
47
if ( counter != 1 ) {
44
48
document . getElementById ( "result" ) . innerText = "Bang! You survived " + counter + " clicks" ;
45
- } else {
46
- document . getElementById ( "result" ) . innerText = "Bang! You survived " + counter + " click" ;
47
49
}
48
50
if ( counter > record ) {
49
51
record = counter ;
50
52
if ( record != 1 ) {
51
- document . getElementById ( "result" ) . innerText = "A New Record! " + counter + " clicks" ;
52
- } else {
53
- document . getElementById ( "result" ) . innerText = "Bang! You survived " + counter + " click" ;
53
+ document . getElementById ( "result" ) . innerText = "A New Record! " + counter + " clicks" ;
54
54
}
55
55
document . getElementById ( "record" ) . innerText = counter ;
56
56
}
57
- document . getElementsByTagName ( "button" ) [ 0 ] . innerText = "Try Again!"
58
57
document . getElementById ( "result" ) . style . color = "red" ;
59
58
document . getElementById ( "count" ) . innerText = counter ;
59
+ document . getElementById ( "buttons" ) . style . display = "none" ;
60
+ document . getElementById ( "reset" ) . style . display = "block" ;
60
61
counter = 0 ;
61
62
state = false ;
62
63
} else {
@@ -65,9 +66,13 @@ <h2>Record: <span id="record">0</span></h2>
65
66
document . getElementById ( "result" ) . innerText = "Lucky!"
66
67
counter += 1 ;
67
68
document . getElementById ( "count" ) . innerText = counter ;
68
- document . getElementsByTagName ( "button" ) [ 0 ] . innerText = "Click Me"
69
69
}
70
70
}
71
+ function reset ( ) {
72
+ document . getElementById ( "buttons" ) . style . display = "block" ;
73
+ document . getElementById ( "reset" ) . style . display = "none" ;
74
+ document . getElementById ( "result" ) . innerText = "Click Any Of The Buttons And Try Your Luck!" ;
75
+ }
71
76
</ script >
72
77
</ body >
73
- </ html>
78
+ </ html>
0 commit comments