Konami Code

In this example below you will see how to do a Konami Code with some HTML / CSS and Javascript

This awesome code was written by jmm, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright jmm ©
  • HTML
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

  <meta charset="UTF-8">
  <title>Konami Code</title>



    <script  src="js/index.js"></script>



/*Downloaded from https://www.codeseek.co/jmm/konami-code-jYMXqo */
const secretCode = ['ArrowUp', 'ArrowUp', 'ArrowDown', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'ArrowLeft', 'ArrowRight', 'b', 'a', 'Enter', ]
let pressedKeys = [];

window.addEventListener('keyup', (e) => {
  const matchSoFar = pressedKeys.reduce((previous, value, i) => previous && value === secretCode[i], true);

  if (!matchSoFar) {
    pressedKeys = [];
  } else if (pressedKeys.length === secretCode.length) {
    document.body.innerHTML = '<h1>Winner winner, chicken dinner!</h1>';
    pressedKeys = [];