File tree Expand file tree Collapse file tree 1 file changed +57
-0
lines changed
12 - Key Sequence Detection Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Original file line number Diff line number Diff line change 4
4
< meta charset ="UTF-8 ">
5
5
< title > Key Detection</ title >
6
6
< script type ="text/javascript " src ="http://www.cornify.com/js/cornify.js "> </ script >
7
+
8
+ < style >
9
+ html , body {
10
+ height : 100% ;
11
+ min-height : 100% ;
12
+ }
13
+ body {
14
+ display : table;
15
+ width : 100% ;
16
+ background-color : # EEE ;
17
+ }
18
+ .main {
19
+ display : table-cell;
20
+ vertical-align : middle;
21
+ color : # 333 ;
22
+ font-family : "Helvetica Neue" , Helvetica, sans-serif;
23
+ text-align : center;
24
+ }
25
+ .main p {
26
+ margin : 0 0 0.5em ;
27
+ font-size : 1.5em ;
28
+ }
29
+ .main code {
30
+ padding : 0.375em 0.5em ;
31
+ margin : 0 0.175em ;
32
+ font-size : 1rem ;
33
+ background-color : # DDD ;
34
+ }
35
+ </ style >
7
36
</ head >
8
37
< body >
38
+
39
+ < div class ="main ">
40
+ < p > Enter the secret code.</ p >
41
+ < small > The secret code is < code > unicorn</ code > !!!</ small >
42
+ </ div >
43
+
9
44
< script >
45
+ const pressed = [ ] ;
46
+ const secretCode = 'unicorn' ;
47
+
48
+ window . addEventListener ( 'keyup' , ( e ) => {
49
+ // console.log(e.key);
50
+
51
+ pressed . push ( e . key ) ;
52
+ pressed . splice ( - secretCode . length - 1 , pressed . length - secretCode . length ) ;
53
+
54
+ if ( pressed . join ( '' ) . includes ( secretCode ) ) {
55
+ console . log ( 'You did it!' ) ;
56
+ console . log ( 'Here are some unicorns:' ) ;
57
+
58
+ // let's add unicorns 30 times
59
+ for ( x = 1 ; x <= 30 ; x ++ ) {
60
+ cornify_add ( ) ;
61
+ }
62
+ }
63
+
64
+ console . log ( pressed ) ;
65
+ } ) ;
10
66
</ script >
67
+
11
68
</ body >
12
69
</ html >
You can’t perform that action at this time.
0 commit comments