forked from wesbos/JavaScript30
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added notes and solution for Project 12 - KONAMI code
- Loading branch information
1 parent
daf627c
commit 8154707
Showing
2 changed files
with
45 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,35 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Key Detection</title> | ||
<script type="text/javascript" src="http://www.cornify.com/js/cornify.js"></script> | ||
<meta charset="UTF-8"> | ||
<title>Key Detection</title> | ||
<script type="text/javascript" src="http://www.cornify.com/js/cornify.js"></script> | ||
</head> | ||
|
||
<body> | ||
<script> | ||
</script> | ||
<script> | ||
|
||
const pressed = []; | ||
const secretCode = 'cooljs'; | ||
|
||
function keyLog(e) { | ||
pressed.push(e.key); | ||
pressed.splice(-secretCode.length -1, pressed.length - secretCode.length) | ||
console.log(pressed); | ||
|
||
// if user enters the secretCode, give them some 🦄 unicorn love! | ||
if (pressed.join('').includes(secretCode)) { | ||
console.clear(); | ||
console.warn('DING DING DING!!! You found the secret code!') | ||
cornify_add(); | ||
} | ||
} | ||
|
||
// Add event listener to track keys pressed | ||
window.addEventListener('keyup', keyLog) | ||
|
||
</script> | ||
</body> | ||
</html> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters