-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
112 lines (88 loc) · 2.92 KB
/
script.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
const quiz = new Quiz(sorular);
const ui = new UI();
ui.btn_start.addEventListener("click", function() {
ui.quiz_box.classList.add("active");
startTimer(10);
startTimerLine();
ui.soruGoster(quiz.soruGetir());
ui.soruSayisiniGoster(quiz.soruIndex + 1, quiz.sorular.length);
ui.btn_next.classList.remove("show");
});
ui.btn_next.addEventListener("click", function() {
if (quiz.sorular.length != quiz.soruIndex + 1) {
quiz.soruIndex += 1;
clearInterval(counter);
clearInterval(counterLine);
startTimer(10);
startTimerLine();
ui.soruGoster(quiz.soruGetir());
ui.soruSayisiniGoster(quiz.soruIndex + 1, quiz.sorular.length);
ui.btn_next.classList.remove("show");
} else {
clearInterval(counter);
clearInterval(counterLine);
ui.quiz_box.classList.remove("active");
ui.score_box.classList.add("active");
ui.skoruGoster(quiz.sorular.length, quiz.dogruCevapSayisi);
}
});
ui.btn_quit.addEventListener("click", function() {
window.location.reload();
});
ui.btn_replay.addEventListener("click", function() {
quiz.soruIndex = 0;
quiz.dogruCevapSayisi = 0;
ui.btn_start.click();
ui.score_box.classList.remove("active");
});
function optionSelected(option) {
clearInterval(counter);
clearInterval(counterLine);
let cevap = option.querySelector("span b").textContent;
let soru = quiz.soruGetir();
if(soru.cevabiKontrolEt(cevap)) {
quiz.dogruCevapSayisi += 1;
option.classList.add("correct");
option.insertAdjacentHTML("beforeend", ui.correctIcon);
} else {
option.classList.add("incorrect");
option.insertAdjacentHTML("beforeend", ui.incorrectIcon);
}
for(let i=0; i < ui.option_list.children.length; i++) {
ui.option_list.children[i].classList.add("disabled");
}
ui.btn_next.classList.add("show");
}
let counter;
function startTimer(time) {
counter = setInterval(timer, 1000);
function timer() {
ui.time_second.textContent = time;
time--;
if(time < 0) {
clearInterval(counter);
ui.time_text.textContent = "Süre Bitti";
let cevap = quiz.soruGetir().dogruCevap;
for(let option of ui.option_list.children) {
if(option.querySelector("span b").textContent == cevap) {
option.classList.add("correct");
option.insertAdjacentHTML("beforeend", ui.correctIcon);
}
option.classList.add("disabled");
}
ui.btn_next.classList.add("show");
}
}
}
let counterLine;
function startTimerLine() {
let line_width = 0;
counterLine = setInterval(timer, 20);
function timer() {
line_width += 1;
ui.time_line.style.width = line_width + "px";
if(line_width > 549) {
clearInterval(counterLine);
}
}
}