I was asked to implement the Konami Code in a website I\'m currently working on. It should do the following:
Change Background Image
Play s
Piggybacking off Ehsan Kia,
I haven't seen anyone handling cases where the up key could be pressed 3+ times, and technically the code would have been input correctly.
Minified it a bit because the conditionals got long.
let c = 0;
const kCode = [38,38,40,40,37,39,37,39,66,65];
document.addEventListener('keydown', (e) => {
c = (e.keyCode == kCode[c] ? c + 1 : (e.keyCode-38 ? 0 : (c ? (kCode[c-1] == 38 ? c : 0) : 0)));
if(c == kCode.length) activate();
});