Created
April 9, 2022 13:47
-
-
Save egdoc/d4f615b257fb1a63c2abdd4c0fe95824 to your computer and use it in GitHub Desktop.
Example of Konami code implementation in Javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| document.addEventListener('DOMContentLoaded', function() { | |
| 'use strict'; | |
| const konami_code = [ 'ArrowUp', 'ArrowUp', 'ArrowDown', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'ArrowLeft', 'ArrowRight', 'b', 'a']; | |
| let konami_position = 0; | |
| document.addEventListener('keydown', function (event) { | |
| if (konami_code[konami_position] == event.key) { | |
| konami_position += 1; | |
| if (konami_position == konami_code.length) { | |
| alert("Konami code activated!"); | |
| } | |
| } else { | |
| konami_position = 0; | |
| } | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment