Skip to content

Commit 775b52b

Browse files
author
mochibot
committed
finished tutorial 12. Used konami code as secret code
1 parent eefd1df commit 775b52b

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Things learned:
2+
- for array.splice(), if index if negative, it will begin that many elements from the end (for example, x.splice(-1, 1) starts 1 element from the end of x and deletes a single element)
3+
- cornify_add()

12 - Key Sequence Detection/index-START.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@
77
</head>
88
<body>
99
<script>
10+
let pressed = [];
11+
let secretCode = ['ArrowUp', 'ArrowUp', 'ArrowDown', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'ArrowLeft', 'ArrowRight', 'b', 'a']
12+
13+
window.addEventListener('keyup', (event) => {
14+
pressed.push(event.key);
15+
pressed.splice(-secretCode.length - 1, pressed.length - secretCode.length);
16+
console.log(pressed);
17+
if (pressed.join('') === secretCode.join('')) {
18+
cornify_add();
19+
}
20+
})
21+
1022
</script>
1123
</body>
1224
</html>

0 commit comments

Comments
 (0)