Skip to content

Instantly share code, notes, and snippets.

@egdoc
Created April 9, 2022 13:47
Show Gist options
  • Select an option

  • Save egdoc/d4f615b257fb1a63c2abdd4c0fe95824 to your computer and use it in GitHub Desktop.

Select an option

Save egdoc/d4f615b257fb1a63c2abdd4c0fe95824 to your computer and use it in GitHub Desktop.
Example of Konami code implementation in Javascript
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