Skip to content

Commit 7506ae6

Browse files
committed
Day 12.
1 parent 0a64c90 commit 7506ae6

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Key Detection</title>
6+
</head>
7+
<body>
8+
9+
<script>
10+
const keySequence = [
11+
'ArrowUp',
12+
'ArrowUp',
13+
'ArrowDown',
14+
'ArrowDown',
15+
'ArrowLeft',
16+
'ArrowRight',
17+
'ArrowLeft',
18+
'ArrowRight',
19+
'b',
20+
'a',
21+
];
22+
23+
let userInput = new Array( keySequence.length );
24+
25+
window.addEventListener( 'keydown', ( { key } ) => {
26+
userInput = [ ...userInput.slice( 1 ), key ];
27+
28+
if ( keySequence.every( ( v, k ) => v === userInput[ k ] ) ) {
29+
alert( 'Yatta!' );
30+
}
31+
} );
32+
</script>
33+
34+
</body>
35+
</html>

0 commit comments

Comments
 (0)