Advertisement
Guest User

Javascript Konami Code

a guest
Mar 30th, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if (window.addEventListener) {
  2.     keys = [], code = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65];
  3.  
  4.     window.addEventListener("keyup", function(e) {
  5.         keys.push(e.keyCode);
  6.         if (keys.length > code.length) {
  7.             keys.shift();
  8.         }
  9.  
  10.         if (keys.length == code.length) {
  11.             if (keys.toString() == code.toString()) {
  12.                 console.log("you did it!");
  13.             }
  14.         }
  15.     });
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement