forked from irwan941/game-ngetik
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
113 lines (103 loc) · 2.09 KB
/
index.js
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
let point = 0;
let waktu = 5;
let gameIsOver;
let currentWord;
let mulai = false;
const kata = [
"mungkin",
"ini",
"memang",
"jalan",
"takdirku",
"mengagumi",
"tanpa",
"dicintai",
"tak",
"mengapa",
"bagiku",
"asal",
"kau",
"pun",
"bahagia",
"dalam",
"hidupmu",
"dalam",
"hidupmu",
"telah",
"lama",
"ku",
"pendam",
"perasaan",
"itu",
"menunggu",
"hatimu",
"menyambut",
"diriku",
"tak",
"mengapa",
"bagiku",
"mencintaimu",
"pun",
"adalah",
"bahagia",
"untukku",
"bahagia",
"untukku",
"ku",
"ingin",
"kau",
"tahu"
];
const sePoint = document.querySelector("#point");
const seWaktu = document.querySelector("#waktu");
const seCurrentKata = document.querySelector("#currentkata");
const seInputKata = document.querySelector("#inputKata");
const seGameOver = document.querySelector("#game-over");
const seRestart = document.querySelector("#restart");
document.addEventListener("DOMContentLoaded", init);
seRestart.addEventListener("click", e => {
e.preventDefault();
gameIsOver = false;
waktu = 5;
seInputKata.disabled = false;
seInputKata.focus();
seRestart.style.display = "none";
seGameOver.style.display = "none";
init;
});
function init() {
setInterval(handleChangeWaktu, 1000);
handlePilihKata();
}
function handlePilihKata() {
currentWord = kata[Math.floor(Math.random() * (kata.length - 1 - 0 + 1))];
console.log(currentWord);
seCurrentKata.innerHTML = currentWord;
}
function handleInputkata() {
console.log(seInputKata.value);
if (seInputKata.value === currentWord) {
console.log("sama");
handlePilihKata();
seInputKata.value = "";
waktu = 6;
point = point + 10;
sePoint.innerHTML = point;
console.log(point);
}
}
function handleChangeWaktu() {
console.log(waktu);
if (seInputKata === document.activeElement) {
if (waktu === 0) {
gameIsOver = true;
seGameOver.style.display = "block";
seRestart.style.display = "inline";
seInputKata.disabled = true;
} else {
waktu--;
seWaktu.innerHTML = waktu;
handleInputkata();
}
}
}