Skip to content

Instantly share code, notes, and snippets.

@kentbrew
Last active April 18, 2016 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kentbrew/15d3497cd2509181014c69afc8ef90dc to your computer and use it in GitHub Desktop.
Save kentbrew/15d3497cd2509181014c69afc8ef90dc to your computer and use it in GitHub Desktop.
Problem-Solving Interview Question: Implementing the Konami Code

#Implementing the Konami Code

The Konami Code is a cheat code that appears in many early Konami video games. During the title screen before the game demo begins, the player can press the following sequence of buttons on the game controller to enable the cheat:

###↑ ↑ ↓ ↓ ← → ← → B A [Start]

The code has also found a place in popular culture as a reference to the third generation of video game consoles, and is present as an Easter egg on a number of Web sites.

####Please implement the Konami Code in JavaScript.

To test your code, we will open a console window onto a Web page, copy your code, paste it into the console, and hit Enter. When the Konami code is successfully entered, your code should do this:

console.log('Konami!');

####Your Code Should Be:

Robust. We'll test by trying out correct and incorrect strings of keypresses on current versions of Chrome, Edge, Firefox, Internet Explorer, Konqueror, Safari, and Opera.

Invisible. Your code should not be easily detectable by other scripts running on the same page. Among other things, don't alter the DOM, steal global event listeners, or make any network requests after loading.

Independent. Don't include or require any libraries, as they a) require network requests and b) tend not to be invisible once running.

Readable. Other engineers should be able to look at your code and understand it.

Maintainable. If we decide we need to change the Konami code into another string of characters, we should be able to do so easily.

####Resources:

Please use any Internet resource you find useful. Stack Overflow, the Mozilla Developer Network, and Quirksmode are some of our favorites.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment