-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
90 lines (62 loc) · 2.11 KB
/
script.js
File metadata and controls
90 lines (62 loc) · 2.11 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
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
const tblretry = document.querySelector('.score #retry');
const tblkembali = document.querySelector('.score #kembali');
const mulai = document.getElementById('mulai');
let i = 0;
let correct = 0;
soal(0);
timeplay = 30;
let timercounter;
mulai.onclick = ()=>{
document.querySelector('.wrapper').style.display = "block";
document.querySelector('.start').style.display = "none";
timer(timeplay);
}
tblkembali.onclick = ()=>{
location.reload();
}
tblretry.onclick = ()=>{
correct = 0;
i = 0;
soal(0);
document.querySelector('.score').style.display = "none";
document.querySelector('.wrapper').style.display = "block";
timer(timeplay);
}
function soal(index){
document.querySelector('.quest').innerHTML = question[index].quest;
document.getElementById('anss1').innerHTML = question[index].answer1;
document.getElementById('anss2').innerHTML = question[index].answer2;
document.getElementById('anss3').innerHTML = question[index].answer3;
}
function score(){
if (document.getElementById('ans1').checked && question[i].answer1 == question[i].rights) {
correct++;
}
if (document.getElementById('ans2').checked && question[i].answer2 == question[i].rights) {
correct++;
}
if (document.getElementById('ans3').checked && question[i].answer3 == question[i].rights) {
correct++;
}
i++
if (question.length-1 < i) {
document.querySelector('.score p').innerHTML = "Selamat kamu mendapatkan score "+correct+"/10";
document.querySelector('.score').style.display = "block";
document.querySelector('.wrapper').style.display = "none";
clearInterval(timercounter);
}
soal(i);
}
function timer(time){
timercounter = setInterval(timers, 1000);
function timers(){
document.querySelector('.wrapper .timer span').textContent = time;
time--;
if (time < 0) {
document.querySelector('.score p').innerHTML = "Selamat kamu mendapatkan score "+correct+"/10";
document.querySelector('.score').style.display = "block";
document.querySelector('.wrapper').style.display = "none";
clearInterval(timercounter);
}
}
}