// A key map of allowed keys var allowedKeys = { 8: 'backspace' }; // The sequence var oopsCode = ['backspace']; // A variable to remember the 'position' the user has reached so far. var oopsCodePosition = 0; // Add keydown event listener document.addEventListener('keydown', function (e) { // Get the value of the key code from the key map var key = allowedKeys[e.keyCode]; // Get the value of the required key from the oops Code var requiredKey = oopsCode[oopsCodePosition]; // Compare the key with the required key if (key == requiredKey) { // Move to the next key in the oops Code sequence oopsCodePosition++; // Ff the last key is reached, activate cheats if (oopsCodePosition == oopsCode.length) { activateCheats(); oopsCodePosition = 0; } } else { oopsCodePosition = 0; } }); function activateCheats() { window.location.href = "/oops.html"; }