-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
55 lines (47 loc) · 1.59 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<title>KlikDaily-Test</title>
<script type="text/javascript">
let questions = ['tikus', 'kerbau', 'harimau', 'kelinci', 'naga', 'ular', 'kuda', 'kambing', 'monyet', 'ayam', 'anjing', 'babi'];
let questionIndex = null,
tempQuestion = null,
tempAnswer = null,
tmp = null;
function init() {
questionIndex = Math.floor(Math.random() * 12);
tempAnswer = questions[questionIndex];
tempQuestion = questions[questionIndex];
question = shuffle(tempQuestion);
document.getElementById('question').innerHTML = question;
}
function shuffle(tempQuestion) {
tempQuestion = tempQuestion.split("");
for(let i = tempQuestion.length - 1; i > 0; i--) {
let j = Math.floor(Math.random() * i);
tmp = tempQuestion[i];
tempQuestion[i] = tempQuestion[j];
tempQuestion[j] = tmp;
}
return tempQuestion.join("");
}
function check() {
if (document.getElementById('answer').value == '') {
document.getElementById('check').innerHTML = 'ANSWER IS EMPTY';
} else if (document.getElementById('answer').value !== tempAnswer) {
document.getElementById('check').innerHTML = 'WRONG ANSWER';
} else {
document.getElementById('check').innerHTML = 'CORRECT ANSWER';
init();
}
}
</script>
</head>
<body>
<button onclick="init()">Get Question</button> <br>
Kata acak: <label id="question"></label> <br>
Jawaban: <input type="text" id="answer" name="answer"> <br>
<button onclick="check()">Check</button>
<label id="check"></label>
</body>
</html>