Skip to content

Commit 74b30a8

Browse files
committed
πŸ¦„ Unicorn Rain 🌈
1 parent 67bfd70 commit 74b30a8

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

Diff for: β€Ž12 - Key Sequence Detection/index-START.html

+44-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,53 @@
33
<head>
44
<meta charset="UTF-8">
55
<title>Key Detection</title>
6-
<script type="text/javascript" src="http://www.cornify.com/js/cornify.js"></script>
6+
<script type="text/javascript" src="https://www.cornify.com/js/cornify.js"></script>
77
</head>
88
<body>
9+
<h1>Press Enter</h1>
910
<script>
11+
const pressed = [],
12+
str = 'marco',
13+
strArr = [...str.split(''), 'S'];
14+
15+
window.addEventListener('keyup', (e) => {
16+
const strLength = str.length;
17+
if ( 'Enter' == e.key ) {
18+
rainUnicorn()
19+
}
20+
pressed.push(e.key);
21+
console.groupCollapsed()
22+
console.log( 'e.key: ', e.key );
23+
console.log( 'strLength: ', strLength );
24+
console.log( 'pressed.length: ', pressed.length );
25+
let splice = pressed.splice(-strLength -1, pressed.length - strLength),
26+
joined = pressed.join('');
27+
console.log( 'pressed.length after splice: ', pressed.length );
28+
console.log( 'splice: ', splice );
29+
console.log( 'joined: ', joined );
30+
console.groupEnd()
31+
if ( joined.includes(str) ) {
32+
cornify_add();
33+
}
34+
});
35+
36+
function unicorn(arr) {
37+
arr
38+
.map(char => ({ code : char.charCodeAt(), char : char }) )
39+
.forEach(key => window.dispatchEvent (
40+
new KeyboardEvent('keyup', { 'keyCode':key.code, 'key':key.char })
41+
));
42+
}
43+
function rainUnicorn() {
44+
let arr = [];
45+
for(var i = 0; i < 88; i++){
46+
arr = [...arr, ...strArr];
47+
}
48+
unicorn(arr);
49+
}
50+
51+
unicorn(strArr);
52+
1053
</script>
1154
</body>
1255
</html>

0 commit comments

Comments
Β (0)