-
Notifications
You must be signed in to change notification settings - Fork 0
/
result.js
39 lines (37 loc) · 1.11 KB
/
result.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
var generateResult = document.getElementById("sub-btn");
var answers = document.querySelectorAll('input[type="radio"]');
var score = 0;
var nextBtn = document.getElementById("nxt-btn");
generateResult.addEventListener("click", function(){
generateResult.disabled="true";
for(let item of answers){
if(item.checked){
if(item.value=="correct"){
score+=1;
let iD = item.getAttribute("data-span-id");
let circleCheck = document.getElementById(iD);
circleCheck.classList.add("show");
}
else{
item.nextElementSibling.classList.add("colRed");
let iD = item.getAttribute("data-span-id");
let circleWrong = document.getElementById(iD);
circleWrong.classList.add("show");
}
}
if(item.value=="correct"){
item.nextElementSibling.classList.add("colGreen");
}
item.disabled="true";
}
let message = "You have scored " + score*10 + "%";
alert(message);
});
nextBtn.addEventListener("click", function(){
if(score<8){
alert("Score 80% or more to proceed to next stage")
}
else{
window.location.href=nextBtn.getAttribute("data-next-page");
}
});