Konami Code (Simplified)
HTML
<h1>THE GREATEST CHEAT CODE IN HISTORY</h1>
CSS
body {
background-color: hsl( 0, 0%, 20% );
color: hsl( 0, 0%, 80% );
font-family: Futura, Arial, sans-serif;
font-size: 48px;
text-align: center;
text-shadow: 2px 2px 0 hsl( 0, 0%, 0% );
}
JavaScript
// Implement the Konami Code on a webpage
//
// This is the first way that it occurred to me to do it. I am 100% sure there are other
// interesting and undoubtedly better ways. Show me how you would do it.
(function($) {
var cheatProgress = 0,
// An array of the keycodes for the code
code = [
// up up down down left right left right b a
38, 38, 40, 40, 37, 39, 37, 39, 66, 65
];
$( document ).bind( 'keydown.konami', function( event ) {
if ( event.keyCode === code[ cheatProgress ] ) {
if ( cheatProgress === code.length - 1 ) {
// Trigger success event
$( document ).trigger( 'cheat.konami' );
// Reset progress
cheatProgress = 0;
} else {
cheatProgress += 1;
}
} else {
// If the wrong key's been entered, reset progress
cheatProgress = 0;
}
});
// The rest is just deciding what to bind to the cheat custom event
$( document ).bind( 'cheat.konami', function() {
$( 'body' ).css({
'background-color': 'hsl( 0, 50%, 50% )'
})
.children( 'h1' )
.text( '30 LIVES' );
});
})( jQuery );