-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkonami.html
More file actions
54 lines (45 loc) · 1.49 KB
/
konami.html
File metadata and controls
54 lines (45 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<!DOCTYPE html>
<html lang="en">
<head>
<title>Konami Code</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<h1>Konami Code</h1>
<script>
"use strict";
let keysEntered = [];
let konamiCode = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65, 13]; // Konami Code: Up, Up, Down, Down, Left, Right, Left, Right, B, A, Enter
let backgroundNoColor = "lightblue";
let backgroundYesColor = "red";
let playGame = confirm("Do you want to play a game?");
if (playGame) {
document.body.style.backgroundColor = backgroundYesColor;
$(document).keyup(function(event){
keysEntered.push(event.keyCode);
if (keysEntered.length > konamiCode.length) {
keysEntered.shift();
}
if (arraysEqual(keysEntered, konamiCode)) {
alert("You have added 30 lives!");
// Add your additional actions here
keysEntered = []; // Reset the keysEntered array
}
});
} else {
document.body.style.backgroundColor = backgroundNoColor;
let reason = prompt("Why don't you want to play a game?");
console.log("Reason: " + reason);
}
function arraysEqual(arr1, arr2) {
if (arr1.length !== arr2.length)
return false;
for (let i = 0; i < arr1.length; i++) {
if (arr1[i] !== arr2[i])
return false;
}
return true;
}
</script>
</body>
</html>