-
Notifications
You must be signed in to change notification settings - Fork 3
/
Percentage.js
341 lines (310 loc) · 11.5 KB
/
Percentage.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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
var percentage = NaN
var centered = false
function calculate() {
var inputs = document.getElementsByTagName('input')
for (var i = 0; i < inputs.length; i++) {
if (isNaN(parseInt(inputs[i].value))) {
return
}
}
// 10th Grade
var tenth = calculate10()*0.3
// 11th Grade
var eleventh = calculate11()*0.3
// 12th Grade Practicals
var practical = calculatepr()
// 12th Grade Unit Test
var unittest = calculateut()
// 12th Grade Midterm Exam
var midterm = calculatemt()
//12th Grade Pre-Board Exams
var preboard = calculatepb()
var twelfth = ((practical + unittest + midterm + preboard) / 4) * 0.4
var final_marks = (tenth + eleventh + twelfth)
var marks = document.getElementsByTagName('h2')[0]
final_marks = Math.round(final_marks * 1000) / 1000
percentage = final_marks
marks.innerHTML = "Your Percentage is: " + final_marks + " %"
}
function calculate10() {
var first10 = parseInt(document.getElementById('first10').value, 10)
var second10 = parseInt(document.getElementById('second10').value, 10)
var third10 = parseInt(document.getElementById('third10').value, 10)
var tenth = (first10 + second10 + third10) / 3
return tenth
}
function calculate11() {
var first11 = parseInt(document.getElementById('first11').value, 10)
var second11 = parseInt(document.getElementById('second11').value, 10)
var third11 = parseInt(document.getElementById('third11').value, 10)
var fourth11 = parseInt(document.getElementById('fourth11').value, 10)
var fifth11 = parseInt(document.getElementById('fifth11').value, 10)
var eleventh = ((first11 + second11 + third11 + fourth11 + fifth11) / 5.0)
return eleventh
}
function calculatepr() {
var firstpr12 = parseInt(document.getElementById('firstpr12').value, 10)
var secondpr12 = parseInt(document.getElementById('secondpr12').value, 10)
var thirdpr12 = parseInt(document.getElementById('thirdpr12').value, 10)
var fourthpr12 = parseInt(document.getElementById('fourthpr12').value, 10)
var fifthpr12 = parseInt(document.getElementById('fifthpr12').value, 10)
var practical = ((firstpr12 + secondpr12 + thirdpr12 + fourthpr12 + fifthpr12) / 1.3)
return practical
}
function calculateut() {
var firstut12 = parseInt(document.getElementById('firstut12').value, 10)
var secondut12 = parseInt(document.getElementById('secondut12').value, 10)
var thirdut12 = parseInt(document.getElementById('thirdut12').value, 10)
var fourthut12 = parseInt(document.getElementById('fourthut12').value, 10)
var fifthut12 = parseInt(document.getElementById('fifthut12').value, 10)
var unittest = ((firstut12 + secondut12 + thirdut12 + fourthut12 + fifthut12) / 1.85)
return unittest
}
function calculatemt() {
var firstmt12 = parseInt(document.getElementById('firstmt12').value, 10)
var secondmt12 = parseInt(document.getElementById('secondmt12').value, 10)
var thirdmt12 = parseInt(document.getElementById('thirdmt12').value, 10)
var fourthmt12 = parseInt(document.getElementById('fourthmt12').value, 10)
var fifthmt12 = parseInt(document.getElementById('fifthmt12').value, 10)
var midterm = ((firstmt12 + secondmt12 + thirdmt12 + fourthmt12 + fifthmt12) / 3.7)
return midterm
}
function calculatepb() {
var firstpb12 = parseInt(document.getElementById('firstpb12').value, 10)
var secondpb12 = parseInt(document.getElementById('secondpb12').value, 10)
var thirdpb12 = parseInt(document.getElementById('thirdpb12').value, 10)
var fourthpb12 = parseInt(document.getElementById('fourthpb12').value, 10)
var fifthpb12 = parseInt(document.getElementById('fifthpb12').value, 10)
var preboard = ((firstpb12 + secondpb12 + thirdpb12 + fourthpb12 + fifthpb12) / 3.7)
return preboard
}
function check10(Id) {
var f = parseInt(document.getElementById(Id).value, 10)
if (isNaN(f)) {
if (document.getElementById(Id).value != '') {
alert('Please enter numbers only')
document.getElementById(Id).value = ''
return
}
}
if (f > 100) {
document.getElementById(Id).value = ''
alert('10th Grade Marks must be lesser than 100')
}
calculate()
display('tenth')
}
function check11(Id) {
var f = parseInt(document.getElementById(Id).value, 10)
if (isNaN(f)) {
if (document.getElementById(Id).value != '') {
alert('Please enter numbers only')
document.getElementById(Id).value = ''
return
}
}
if (f > 100) {
document.getElementById(Id).value = ''
alert('11th Grade Marks must be lesser than 100')
}
calculate()
display('eleventh')
}
function check12_70(Id) {
var f = parseInt(document.getElementById(Id).value, 10)
if (isNaN(f)) {
if (document.getElementById(Id).value != '') {
alert('Please enter numbers only')
document.getElementById(Id).value = ''
return
}
}
if (f > 70) {
document.getElementById(Id).value = ''
alert('There must be 3 subjects graded out of 70 and 2 subjects graded out of 80 in 11th & 12th Grade Exams')
}
calculate()
if (Id.includes('mt')) {
display('midterm')
}
else if (Id.includes('pb')){
display('preboard')
}
}
function check12_80(Id) {
var f = parseInt(document.getElementById(Id).value, 10)
if (isNaN(f)) {
if (document.getElementById(Id).value != '') {
alert('Please enter numbers only')
document.getElementById(Id).value = ''
return
}
}
if (f > 80) {
document.getElementById(Id).value = ''
alert('There must be 3 subjects graded out of 70 and 2 subjects graded out of 80 in 11th & 12th Grade Exams')
}
calculate()
if (Id.includes('mt')) {
display('midterm')
}
else if (Id.includes('pb')){
display('preboard')
}
}
function check12ut_35(Id){
var f = parseInt(document.getElementById(Id).value, 10)
if (isNaN(f)) {
if (document.getElementById(Id).value != '') {
alert('Please enter numbers only')
document.getElementById(Id).value = ''
return
}
}
if (f > 35) {
document.getElementById(Id).value = ''
alert('There must be 3 subjects graded out of 35 and 2 subjects graded out of 40 in 12th Grade Unit Test')
}
calculate()
display('unittest')
}
function check12ut_40(Id){
var f = parseInt(document.getElementById(Id).value, 10)
if (isNaN(f)) {
if (document.getElementById(Id).value != '') {
alert('Please enter numbers only')
document.getElementById(Id).value = ''
return
}
}
if (f > 40) {
document.getElementById(Id).value = ''
alert('There must be 3 subjects graded out of 35 and 2 subjects graded out of 40 in 12th Grade Unit Test')
}
calculate()
display('unittest')
}
function check12pr20(Id) {
var f = parseInt(document.getElementById(Id).value, 10)
if (isNaN(f)) {
if (document.getElementById(Id).value != '') {
alert('Please enter numbers only')
document.getElementById(Id).value = ''
return
}
}
if (f > 20) {
document.getElementById(Id).value = ''
alert('There must be 3 subjects graded out of 30 and 2 subjects graded out of 20 in 12th Grade Practical Exam')
}
calculate()
display('practical')
}
function check12pr30(Id) {
var f = parseInt(document.getElementById(Id).value, 10)
if (isNaN(f)) {
if (document.getElementById(Id).value != '') {
alert('Please enter numbers only')
document.getElementById(Id).value = ''
return
}
}
if (f > 30) {
document.getElementById(Id).value = ''
alert('There must be 3 subjects graded out of 30 and 2 subjects graded out of 20 in 12th Grade Practical Exam')
}
calculate()
display('practical')
}
function display(what){
var msg = ''
var marks = 0
if (what == 'tenth') {
msg = 'Your 10<sup>th</sup> Grade Board Exam Percentage is: '
marks = Math.round(calculate10()*1000) / 1000
if (!isNaN(marks)) {
document.getElementsByTagName('h2')[0].style.color = '#EA4A86'
}
}
else if (what == 'eleventh') {
msg = 'Your 11<sup>th</sup> Grade Final Exam Percentage is: '
marks = Math.round(calculate11()*1000) / 1000
if (!isNaN(marks)) {
document.getElementsByTagName('h2')[0].style.color = '#61892F'
}
}
else if (what == 'practical') {
msg = 'Your 12<sup>th</sup> Grade Practical Exam Percentage is: '
marks = Math.round(calculatepr()*1000) / 1000
if (!isNaN(marks)) {
document.getElementsByTagName('h2')[0].style.color = '#007CC7'
}
}
else if (what == 'unittest') {
msg = 'Your 12<sup>th</sup> Grade Unit Test Percentage is: '
marks = Math.round(calculateut()*1000) / 1000
if (!isNaN(marks)) {
document.getElementsByTagName('h2')[0].style.color = '#E27D60'
}
}
else if (what == 'midterm') {
msg = 'Your 12<sup>th</sup> Grade MidTerm Exam Percentage is: '
marks = Math.round(calculatemt()*1000) / 1000
if (!isNaN(marks)) {
document.getElementsByTagName('h2')[0].style.color = '#557A95'
}
}
else if (what == 'preboard') {
msg = 'Your 12<sup>th</sup> Grade Pre-Board Exam Percentage is: '
marks = Math.round(calculatepb()*1000) / 1000
if (!isNaN(marks)) {
document.getElementsByTagName('h2')[0].style.color = '#8860D0'
}
}
if (!isNaN(marks)) {
document.getElementsByTagName('h2')[0].innerHTML = msg + marks + '%'
}
}
function revert() {
document.getElementsByTagName('h2')[0].style.color = '#A3A3A3'
if (!isNaN(percentage)) {
document.getElementsByTagName('h2')[0].innerHTML = "Your 12<sup>th</sup> Grade Board Exam Percentage is: " + percentage + " %"
}
else {
document.getElementsByTagName('h2')[0].innerHTML ='Your 12<sup>th</sup> Grade Board Exam Percentage is: --.--%'
}
document.activeElement.blur();
}
function highlight(Id, status) {
var label = document.getElementById(Id)
if (status == 'enter') {
label.style.opacity = '1.0'
label.style.color = '#FEFEFE'
}
else if (status == 'exit') {
label.style.opacity = '0.85'
label.style.color = '#A5A5A5'
}
}
function center(Id) {
revert_center()
var fieldset = document.getElementById(Id)
fieldset.className = fieldset.className +" center"+fieldset.className
var fieldsets = document.getElementsByTagName('fieldset')
for (var i = 0; i < fieldsets.length; i++) {
if (fieldsets[i].id != Id){
fieldsets[i].style.opacity = '0.3'
}
}
centered = true
}
function revert_center() {
if (centered) {
var fieldsets = document.getElementsByTagName('fieldset')
for (var i = 0; i < fieldsets.length; i++) {
fieldsets[i].style.opacity = '1.0'
fieldsets[i].className = fieldsets[i].className.split(" ")[0]
}
centered = false
}
}