-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkonami-code.html
More file actions
60 lines (56 loc) · 1.32 KB
/
konami-code.html
File metadata and controls
60 lines (56 loc) · 1.32 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
55
56
57
58
59
60
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Konami Game</title>
</head>
<body>
<header>
Username: Luis
Score: 1000
Life #: <span id="life">1</span>
</header>
<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"
>
</script>
<script>
"use strict";
var konamiCode = [
38,
38,
40,
40,
37,
39,
37,
39,
66,
65,
13
];
var i = 0;
var lives = parseInt($("#life").text());
// if the Konami code is correct
// I'll change the value of the element #life to 30, change the font color to green make it
// bold
// If the konami code is wrong I'll change the #life element font-color to gray, make it bold
$(document).keyup(function (event) {
if (event.keyCode !== konamiCode[i]) {
$("#life").css("color", "blue").css("font-weight", "bold");
i = 0;
} else {
i++;
}
// if the code is complete ?
if (konamiCode.length === i) {
lives += 30;
$("#life").html(lives + " lives").css("color", "green").css("font-weight", "bold");
i = 0;
}
});
</script>
</body>
</html>