-
Notifications
You must be signed in to change notification settings - Fork 1
/
chemistryscript.js
130 lines (112 loc) · 3.1 KB
/
chemistryscript.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
const timerr = document.getElementById('timer');
var c=120;
setInterval(timer001,1000);
function timer001(){
if(c>0){
timerr.innerText=c;
c--;
}
if(c===0){
timerr.innerText=c;
showScore.innerHTML = `
<h3> You Scored ${score}/${quizDB.length} </h3>
<button class="btn" onclick="location.reload()">Play Again</button>
`;
showScore.classList.remove('scoreArea');
}
}
const quizDB = [
{
question: "Q1:Which of the following is not a correct statement about Bitumen?",
a: "It’s a mixture of highly condensed polycyclic aromatic compounds",
b: "Its is soluble in Carbon Disulphide",
c: " SARA analysis is used to determine bitumen chemistry",
d: "All of above are correct statements",
ans: "ans4"
},
{
question: "Q2: Dalton’s name is associated with which of the following terms?",
a: "Electron",
b: "Proton",
c: "Atom",
d: "Neutron",
ans: "ans3"
},
{
question: "Q3:Which gas is used in making of Vanaspati ghee from vegetable oils?",
a: "N2",
b: "NO2",
c: " H2",
d: "Ne",
ans: "ans3"
},
{
question: "Q4: White Phosphorous is represented by which among the following symbols?",
a: " P1",
b: " P2",
c: " P3",
d: " P4",
ans: "ans4"
},
{
question: "Q5:Which among the following is known as White Vitriol?",
a: " Zinc Sulphate",
b: "Zinc Chloride",
c: " Zinc Phosphate",
d: "Zinc oxide",
ans: "ans1"
},
];
const question = document.querySelector('.question');
const option1 = document.querySelector('#option1');
const option2 = document.querySelector('#option2');
const option3 = document.querySelector('#option3');
const option4 = document.querySelector('#option4');
const submit = document.querySelector('#submit');
const answers = document.querySelectorAll('.answer');
const showScore = document.querySelector('#showScore');
let questionCount = 0;
let score =0;
const loadQuestion = () =>
{
const questionList = quizDB[questionCount];
question.innerText = questionList.question;
option1.innerText = questionList.a;
option2.innerText = questionList.b;
option3.innerText = questionList.c;
option4.innerText = questionList.d;
}
loadQuestion();
const getCheckAnswer = () => {
let answer;
answers.forEach((curAnsElem) => {
if(curAnsElem.checked){
answer = curAnsElem.id;
}
})
return answer;
};
const deselectAll = () =>
{
answers.forEach((curAnsElem) => curAnsElem.checked = false );
}
submit.addEventListener('click', () =>
{
const checkedAnswer = getCheckAnswer();
if(checkedAnswer === quizDB[questionCount].ans)
{score++;
};
questionCount++;
deselectAll();
if(questionCount < quizDB.length&&c>0){
loadQuestion();
}
else {
c=0;
showScore.innerHTML = `
<h3> You Scored ${score}/${quizDB.length} </h3>
<button class="btn" onclick="location.reload()">Play Again</button>
`;
showScore.classList.remove('scoreArea');
}
});