-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregexamdisp12.js
220 lines (214 loc) · 10.6 KB
/
regexamdisp12.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/************Obtaining some DOM objects: Input Name, Start Exam Button, Score Page at end , CountDown Timer *********************/
const submit = document.querySelector(".submitData");
const showName= document.querySelector(".showName");
const showScore= document.querySelector(".showScore");
const countDown = document.getElementById('countdown');
/**************Timer Variables, Student Data stored within Array: Name as Object,Score,Number of Correct and Wrong Answered questions*******/
const startminutes = 90;
let time = startminutes*60;
var studentData = [];
var totScore = 0,wrongAttempt = 0, correctAttempt = 0;
/********************Variable for Question Number used to pick Questions from Array questionObjArr : Array of Question Objects*********/
var qNum = 0;
var q1 = new Question("Q1.jpg", "C", "Not Answered", false, 0);
var q2 = new Question("Q2.jpg", "A", "Not Answered", false, 0);
var q3 = new Question("Q3.jpg", "D", "Not Answered", false, 0);
var q4 = new Question("Q4.jpg", "B", "Not Answered", false, 0);
var q5 = new Question("Q5.jpg", "A", "Not Answered", false, 0);
var q6 = new Question("Q6.jpg", "D", "Not Answered", false, 0);
var q7 = new Question("Q7.jpg", "B", "Not Answered", false, 0);
var q8 = new Question("Q8.jpg", "B", "Not Answered", false, 0);
var q9 = new Question("Q9.jpg", "D", "Not Answered", false, 0);
var q10 = new Question("Q10.jpg", "A", "Not Answered", false, 0);
var q11 = new Question("Q11.jpg", "B", "Not Answered", false, 0);
var q12 = new Question("Q12.jpg", "B", "Not Answered", false, 0);
var q13 = new Question("Q13.jpg", "D", "Not Answered", false, 0);
var q14 = new Question("Q14.jpg", "D", "Not Answered", false, 0);
var q15 = new Question("Q15.jpg", "A", "Not Answered", false, 0);
var q16 = new Question("Q16.jpg", "B", "Not Answered", false, 0);
var q17 = new Question("Q17.jpg", "C", "Not Answered", false, 0);
var q18 = new Question("Q18.jpg", "B", "Not Answered", false, 0);
var q19 = new Question("Q19.jpg", "B", "Not Answered", false, 0);
var q20 = new Question("Q20.jpg", "B", "Not Answered", false, 0);
var q21 = new Question("Q21.jpg", "D", "Not Answered", false, 0);
var q22 = new Question("Q22.jpg", "A", "Not Answered", false, 0);
var q23 = new Question("Q23.jpg", "A", "Not Answered", false, 0);
var q24 = new Question("Q24.jpg", "B", "Not Answered", false, 0);
var q25 = new Question("Q25.jpg", "C", "Not Answered", false, 0);
var q26 = new Question("Q26.jpg", "A", "Not Answered", false, 0);
var q27 = new Question("Q27.jpg", "A", "Not Answered", false, 0);
var q28 = new Question("Q28.jpg", "D", "Not Answered", false, 0);
var q29 = new Question("Q29.jpg", "C", "Not Answered", false, 0);
var q30 = new Question("Q30.jpg", "A", "Not Answered", false, 0);
var questionObjArr = [q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, q12, q13, q14, q15, q16, q17, q18, q19, q20, q21, q22, q23, q24, q25, q26, q27, q28, q29, q30];
/***********************Each Question is an Object: Question Object Constructor Function ***************************/
function Question(qPic, crOption, ansOption, markState, score) {
this.qPic = qPic;
this.crOption = crOption;
this.ansOption = ansOption;
this.markState = markState;
this.score = score;
}
/************************Setting Event Listener on Start Exam Button: Enters the input Name in the studentData Array first element**********/
/************If either the First or Last Name is not Input, issues a warning. Only if both is input, then goes on to add a class in CSS*******/
/**********The new Class in CSS changes z-index to bring the Question Page forward, and calls the setInterval function for Timer******************/
submit.addEventListener('click' , ()=> {
if ((document.querySelector(".fName").value == '') || (document.querySelector(".lName").value == '')){
alert("Enter Your Full Name!!");
}
else{
studentData.push({
studentFirstName : document.querySelector(".fName").value ,
studentLastName : document.querySelector(".lName").value
});
// console.log(studentData); // No need to console log
document.body.classList.toggle('questionDisplay');
setInterval(updateCount,1000);
}
});
/**************The Countdown timer function: Need a more accurate method other than setInterval***********************/
/**************This Locks / Disables all the buttons in the Question Page if time runs out, except for the Submit Paper Button************/
function updateCount(){
const minutes = Math.floor(time/60);
let seconds = time % 60;
countDown.innerHTML = `${minutes} min : ${seconds} sec`;
time !== 0? time-- : time;
if(time == 0){
document.getElementById("load-prev").disabled = true;
document.getElementById("load-next").disabled = true;
document.getElementById("saveAnswer").disabled = true;
document.getElementById("clear").disabled = true;
}
}
/*************Disabling the Prebious Question Button when Paper Starts*************************/
document.getElementById("load-prev").disabled = true;
/**************Setting a Bunch of Event Listeners*******************************************/
document.getElementById("saveAnswer").addEventListener("click", () => {
var saveButton = document.getElementById("saveAnswer");
var messageChoice = document.getElementById("choice");
var choices = document.getElementsByName("option");
for (i = 0; i < choices.length; i++) {
if (choices[i].checked) {
questionObjArr[qNum].ansOption = choices[i].value;
messageChoice.innerHTML = questionObjArr[qNum].ansOption;
saveButton.disabled = true;
questionObjArr[qNum].markState = true;
if (choices[i].value == questionObjArr[qNum].crOption) {
questionObjArr[qNum].score = 4;
}
else{
questionObjArr[qNum].score = -1;
}
//console.log(questionObjArr[qNum].score);
}
}
});
document.getElementById("clear").addEventListener("click", () => {
var saveButton = document.getElementById("saveAnswer");
saveButton.disabled = false;
document.getElementById("unchck1").checked = false;
document.getElementById("unchck2").checked = false;
document.getElementById("unchck3").checked = false;
document.getElementById("unchck4").checked = false;
questionObjArr[qNum].markState = false;
questionObjArr[qNum].ansOption = "Not Answered";
document.getElementById("choice").innerHTML = questionObjArr[qNum].ansOption;
questionObjArr[qNum].score = 0;
});
document.getElementById("load-next").addEventListener("click", () => {
qNum = qNum + 1;
document.getElementById("saveAnswer").style.borderColor = "#000";
document.getElementById("load-prev").disabled = false;
document.getElementById("choice").innerHTML = questionObjArr[qNum].ansOption;
if(questionObjArr[qNum].markState == false){
document.getElementById("saveAnswer").disabled = false;
document.getElementById("unchck1").checked = false;
document.getElementById("unchck2").checked = false;
document.getElementById("unchck3").checked = false;
document.getElementById("unchck4").checked = false;
}
else{
document.getElementById("saveAnswer").disabled = true;
var choices = document.getElementsByName("option");
for (i = 0; i < choices.length; i++) {
if (choices[i].value == questionObjArr[qNum].ansOption)
choices[i].checked = true;
else
choices[i].checked = false;
}
}
document.getElementById("qImage").src = `./Electromag/${questionObjArr[qNum].qPic}`;
if (qNum == questionObjArr.length - 1)
document.getElementById("load-next").disabled = true;
});
document.getElementById("load-prev").addEventListener("click", () => {
qNum = qNum - 1;
if(questionObjArr[qNum].markState == true){
document.getElementById("saveAnswer").disabled = true;
document.getElementById("choice").innerHTML = questionObjArr[qNum].ansOption;
document.getElementById("saveAnswer").style.borderColor = "#000";
var choices = document.getElementsByName("option");
for (i = 0; i < choices.length; i++) {
if (choices[i].value == questionObjArr[qNum].ansOption)
choices[i].checked = true;
else
choices[i].checked = false;
}
}
else{
document.getElementById("choice").innerHTML = questionObjArr[qNum].ansOption;
document.getElementById("saveAnswer").disabled = false;
document.getElementById("saveAnswer").style.borderColor = "#000";
document.getElementById("unchck1").checked = false;
document.getElementById("unchck2").checked = false;
document.getElementById("unchck3").checked = false;
document.getElementById("unchck4").checked = false;
}
document.getElementById("qImage").src = `./Electromag/${questionObjArr[qNum].qPic}`;
if (qNum == 0)
document.getElementById("load-prev").disabled = true;
document.getElementById("load-next").disabled = false;
});
document.getElementById("submit").addEventListener("click", () => {
if (time != 0){
if (confirm("Are you sure? Do you want to Submit while you have time?")) {
for (i = 0; i < questionObjArr.length; i++) {
totScore = totScore + questionObjArr[i].score;
if(questionObjArr[i].score == 4)
correctAttempt = correctAttempt + 1;
else if(questionObjArr[i].score == -1)
wrongAttempt = wrongAttempt + 1;
}
studentData.push(totScore);
studentData.push(correctAttempt);
studentData.push(wrongAttempt);
document.querySelector('.reportName').innerHTML = " " + studentData[0].studentFirstName+ " " + studentData[0].studentLastName;
document.querySelector('.reportMarks').innerHTML = studentData[1];
document.querySelector('.reportCorrect').innerHTML = studentData[2];
document.querySelector('.reportIncorrect').innerHTML = studentData[3];
document.body.classList.toggle('finalDisplay');
window.location.href = "#";
}
}
else{
for (i = 0; i < questionObjArr.length; i++) {
totScore = totScore + questionObjArr[i].score;
if(questionObjArr[i].score == 4)
correctAttempt = correctAttempt + 1;
else if(questionObjArr[i].score == -1)
wrongAttempt = wrongAttempt + 1;
}
studentData.push(totScore);
studentData.push(correctAttempt);
studentData.push(wrongAttempt);
document.querySelector('.reportName').innerHTML = " " + studentData[0].studentFirstName+ " " + studentData[0].studentLastName;
document.querySelector('.reportMarks').innerHTML = studentData[1];
document.querySelector('.reportCorrect').innerHTML = studentData[2];
document.querySelector('.reportIncorrect').innerHTML = studentData[3];
document.body.classList.toggle('finalDisplay');
window.location.href = "#";
}
});
document.querySelector('.redirectPage').addEventListener('click', ()=>{
window.location = "index.html";
});