Skip to content

Instantly share code, notes, and snippets.

@leomastoras
Created April 5, 2018 08:27
Show Gist options
  • Save leomastoras/19a7d6b4bfb3922aaade9ee4bc7f288a to your computer and use it in GitHub Desktop.
Save leomastoras/19a7d6b4bfb3922aaade9ee4bc7f288a to your computer and use it in GitHub Desktop.
const keySequence = ['l','o','l'];
let userInput = new Array( keySequence.length );
window.addEventListener( 'keydown', ( { key } ) => {
userInput = [ ...userInput.slice( 1 ), key ];
if ( keySequence.every( ( v, k ) => v === userInput[ k ] ) ) {
alert( 'Yatta!' );
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment