-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
80 lines (59 loc) · 1.94 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
let sunucudanDonen;
var baglanti = new XMLHttpRequest();
baglanti.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
// Typical action to be performed when the document is ready:
sunucudanDonen = JSON.parse(baglanti.responseText)
soruGetir();
}
return sunucudanDonen;
};
baglanti.open("GET", "data.json", true);
baglanti.send();
const goruntulemeAlani = document.getElementById('sinav')
const soru = document.getElementById('soru');
const secenekler = document.getElementsByName('secenek');
const aciklamaA = document.getElementById('aciklamaA');
const aciklamaB = document.getElementById('aciklamaB');
const aciklamaC = document.getElementById('aciklamaC');
const aciklamaD = document.getElementById('aciklamaD');
const gonder = document.getElementById('gonder');
let puan = 0;
let sira=0;
function soruGetir(){
secimiTemizle();
let siradakiSoru = sunucudanDonen.sorular[sira]
soru.innerHTML = siradakiSoru.soru;
aciklamaA.innerText = siradakiSoru.secenekA
aciklamaB.innerText = siradakiSoru.secenekB
aciklamaC.innerText = siradakiSoru.secenekC
aciklamaD.innerText = siradakiSoru.secenekD
}
function secimiTemizle(){
secenekler.forEach(secenek => secenek.checked = false)
}
function secimiAl() {
let secim;
secenekler.forEach(secenek => {
if(secenek.checked) {
secim = secenek.id;
}
})
return secim;
}
gonder.addEventListener('click', ()=> {
let secilen = secimiAl();
if(secilen){
if(secilen == sunucudanDonen.sorular[sira].cevap){
puan++;
}
}
sira++;
if(sira < sunucudanDonen.sorular.length){
soruGetir()
}else {
goruntulemeAlani.innerHTML = `<h2>Sınavı başarıyla tamamladınız. Puanınız ${puan}/${sunucudanDonen.sorular.length}</h2>
<button onclick="location.reload()">Yeniden Başla</button>
`
}
})