I am working on creating a .js file for a website that will trigger the embedding of a video when the konami code is entered: Up, Up, Down, Down, Left, Right, Left, Right, B, A, Start (enter). While entering the correct keys, the webpage should display a message like "keep going". If a wrong key is entered, it should display "wrong, try again" and allow the user to start over.
So far, I have managed to make the JavaScript work such that it displays an alert when the correct code is entered and a different alert for incorrect codes. However, I'm struggling with implementing the part where it prompts the user to try again upon entering the wrong code.
if (window.addEventListener) {
var keys = [],
konami = "38,38,40,40,37,39,37,39,66,65,13";
window.addEventListener("keydown", function(e){
keys.push(e.keyCode);
if (keys.toString().indexOf(konami) >= 0) {
alert('Right');
keys = [];
};
if (keys.toString().indexOf(konami) < 0) {
alert('Wrong');
keys = [];
}
}, true);
Any assistance would be highly appreciated.