-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
48 lines (43 loc) · 1.17 KB
/
App.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
const question = [
"lion",
"tiger",
"cat",
"dog",
"elephant",
"giraffe",
"zebra",
"monkey",
"panda",
"koala",
"kangaroo",
"penguin",
"dolphin",
"whale",
"shark",
"octopus",
"crocodile",
"snake",
"lizard",
];
let questionNumber = Math.floor(Math.random() * question.length);
let questioninit = 0;
let questionlength = question[questionNumber].length;
window.addEventListener("keydown", (event) => {
let keyCode = event.key;
if (questionlength == questionlength - questioninit) {
document.getElementById("start").innerHTML = question[questionNumber]
.substring(questioninit, questionlength);
}
if (question[questionNumber].charAt(questioninit) == keyCode) {
questioninit++;
document.getElementById("start").innerHTML = question[questionNumber]
.substring(questioninit, questionlength);
if (questionlength - questioninit === 0) {
questionNumber = Math.floor(Math.random() * question.length);
questioninit = 0;
questionlength = question[questionNumber].length;
document.getElementById("start").innerHTML = question[questionNumber]
.substring(questioninit, questionlength);
}
}
});