-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBacMarkScriptEL.js
501 lines (461 loc) · 18 KB
/
BacMarkScriptEL.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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
var subjects=["L1", "L2", "MA3", "MA5", "EP", "STS", "GE2", "HI2", "PH2", "CHI", "PHY", "BIO", "HI4", "GE4", "AR4", "MU4", "PH4", "L3", "ECO", "LAT", "L4","ONL", "AGR", "L1A", "L2A", "MAA", "MU2", "AR2", "ICT", "IEC", "SOC", "SCP", "L5", "LBI", "LCH", "LPH", "SPO","DRA","ELE", "ARH"];
//ARH = Art history
var subPeriods, periods, listOpts;
var indexes = [];
var aMarkIDs = [];
var bMarkIDs = [];
var wMarkIDs = [];
var oMarkIDs = [];
function start(){
check();
document.getElementById("step1").addEventListener("change", check);
document.getElementById("step2").addEventListener("change", optErr);
document.getElementById("step3").addEventListener("keyup", function(){subjectMark(indexes,aMarkIDs, bMarkIDs, wMarkIDs, oMarkIDs)});
}
function check(){
let total=3;
let nonComp = 3;
for(var i = 0; i<subjects.length ;i++){
if(document.getElementById(subjects[i]).checked){
subPeriods = document.getElementById(subjects[i]).getAttribute("data-periods");
periods=parseInt(subPeriods);
total = total + periods;
if(i<26){
nonComp= nonComp + periods;
}
}
}
document.getElementById("total").innerHTML= "You have total: "+total +" periods.";
checkErrors(nonComp, total);
}
function addOptions(){
checkW1();
checkW2();
checkW3();
optsW4( "CHI", "PHY", "BIO", "HI4", "GE4", "AR4", "MU4", "PH4", "L3", "ECO", "LAT", "L4","ONL", "AGR");
optsW5( "CHI", "PHY", "BIO", "HI4", "GE4", "AR4", "MU4", "PH4", "L3", "ECO", "LAT", "L4","ONL", "AGR");
checkO1();
optsO2("GE2","GE4","HI2","HI4")
optsO3("STS", "PH2", "CHI", "PHY", "BIO", "PH4", "L3", "L4","ONL","MAA")
optErr();
}
function printSubjects(){
var aMarkID;
var bMarkID;
var wMarkID;
var oMarkID;
indexes = [];
aMarkIDs = [];
bMarkIDs = [];
wMarkIDs = [];
oMarkIDs = [];
var table = "<tr><td><b>Subject</td><td><b>A-Mark</td><td><b>B-Mark</td><td><b>Written</td><td><b>Oral</td><td><b>Final Note</td></tr>";
for( var i = 0; i<arguments.length; i++){
if(document.getElementById(arguments[i]).checked){
aMarkID = i+"A";
bMarkID = i+"B";
aMarkIDs.push(aMarkID);
bMarkIDs.push(bMarkID);
indexes.push(i);
table += "<tr><td>"+arguments[i]+"</td>\
<td><input type='number' id='"+aMarkID+"' min='0' max='10' step='0.1' style='width: 4em;' onkeydown='javascript: return event.keyCode == 69 ? false : true' ></td>\
<td><input type='number' id='"+bMarkID+"' min='0' max='10' step='0.1' style='width: 4em;' onkeydown='javascript: return event.keyCode == 69 ? false : true' ></td>";
var written = false
var oral = false;
var idW, idO;
for(var j = 1; j<6;j++){
var id = "W"+j;
if(document.getElementById(id).value===arguments[i]){
written = true;
idW = id;
}
}
if(written){
wMarkID = i+idW;
table += "<td><input type='number' id='"+wMarkID+"' min='0' max='10' step='0.1' style='width: 4em;' onkeydown='javascript: return event.keyCode == 69 ? false : true' ></td>";
wMarkIDs.push(wMarkID);
}else{
wMarkIDs.push(0);
table +="<td></td>";}
for(var k = 1; k<4;k++){
id = "O"+k;
if(document.getElementById(id).value===arguments[i]){
oral = true;
idO=id;
}
}
if(oral){
oMarkID = i+idO;
table += "<td><input type='number' id='"+oMarkID+"' min='0' max='10' step='0.1' style='width: 4em;' onkeydown='javascript: return event.keyCode == 69 ? false : true' ></td>";
oMarkIDs.push(oMarkID);
}else{
table +="<td></td>";
oMarkIDs.push(0);
}
var noteID= i+"Note";
table +="<td id='"+noteID+"'></td></tr>";
}
}
document.getElementById("step3").style.display="block";
document.getElementById("marks").innerHTML=table;
subjectMark(indexes,aMarkIDs, bMarkIDs, wMarkIDs, oMarkIDs);
}
function subjectMark(i,a,b,w,o){
var note;
var aMarks = [];
var bMarks = [];
var wMarks = [];
var oMarks = [];
for(var k=0; k<i.length;k++){
if(w[k]==0 && o[k]==0){
aMarks[k]=Number(checkNaN(a[k]).toFixed(2));
bMarks[k]=Number(checkNaN(b[k]).toFixed(2));
wMarks[k]=0;
oMarks[k]=0;
note = 0.4*aMarks[k]+ 0.6*bMarks[k];
document.getElementById(i[k]+"Note").innerHTML=Number(note).toFixed(2);
}
if(w[k]==0 && o[k] !=0){
aMarks[k]=Number(checkNaN(a[k]).toFixed(2));
bMarks[k]=Number(checkNaN(b[k]).toFixed(2));
wMarks[k]=0;
oMarks[k]=Number(checkNaN(o[k]).toFixed(2));
var cMark=aMarks[k]*0.4+bMarks[k]*0.6;
note = (Number(cMark).toFixed(2)*0.5+0.15*oMarks[k])/0.65;
document.getElementById(i[k]+"Note").innerHTML=Number(note).toFixed(2);
}
if(w[k]!=0 && o[k]==0){
aMarks[k]=Number(checkNaN(a[k]).toFixed(2));
bMarks[k]=Number(checkNaN(b[k]).toFixed(2));
wMarks[k]=Number(checkNaN(w[k]).toFixed(2));
oMarks[k]=0;
var cMark=aMarks[k]*0.4+bMarks[k]*0.6;
note = (Number(cMark).toFixed(2)*0.5+0.35*wMarks[k])/0.85;
document.getElementById(i[k]+"Note").innerHTML=Number(note).toFixed(2);
}
if(w[k]!=0 && o[k] !=0){
aMarks[k]=Number(checkNaN(a[k]).toFixed(2));
bMarks[k]=Number(checkNaN(b[k]).toFixed(2));
wMarks[k]=Number(checkNaN(w[k]).toFixed(2));
oMarks[k]=Number(checkNaN(o[k]).toFixed(2));
var cMark=aMarks[k]*0.4+bMarks[k]*0.6;
note = Number(cMark).toFixed(2)*0.5+0.35*wMarks[k]+0.15*oMarks[k];
document.getElementById(i[k]+"Note").innerHTML=Number(note).toFixed(2);
}
}
var aSum = 0;
var cSum = 0;
var bSum = 0;
var wSum = 0;
var oSum = 0;
for(j = 0; j<i.length; j++){
cSum = cSum+ 0.4*aMarks[j] + 0.6*bMarks[j];
bSum = bSum + bMarks[j];
wSum = wSum + wMarks[j];
oSum = oSum + oMarks[j];
}
var aAvg = aSum/aMarks.length;
var bAvg = bSum/bMarks.length;
var cAvg =cSum/bMarks.length;
var wAvg = wSum/5;
var oAvg = oSum/3;
cAvg = Math.round(cAvg * 100) / 10;
wAvg = Math.round(wAvg * 100) / 10;
oAvg = Math.round(oAvg * 100) / 10;
var BacMark = (cAvg*0.5+wAvg *0.35+oAvg*0.15);
console.log("C: "+cAvg+ " W: "+wAvg+" O: "+oAvg+" Bac: "+BacMark);
BacMark = Math.round(BacMark * 100) / 100
document.getElementById("bacMark").innerHTML="Your Final Bac Mark: "+BacMark;
}
function checkNaN(id){
var a = Number(document.getElementById(id).value);
if(isNaN(a)){
a = 0;
}
if(a<0 || a>10 ){
alert("The mark needs to be between 1 and 10.")
a = 0;
document.getElementById(id).value=0
}
return a;
}
function checkW1(){
var w1 ="L1";
if(document.getElementById("L1A").checked){
w1 = "L1A";
}
document.getElementById("W1").value=w1;
document.getElementById("W1").innerHTML=w1;
}
function checkW2(){
var w2 = "L2";
if(document.getElementById("L2A").checked){
w2 = "L2A";
}
document.getElementById("W2").value=w2;
document.getElementById("W2").innerHTML=w2;
}
function checkW3(){
var w3 = "MA3";
if(document.getElementById("MA5").checked){
w3 = "MA5";
}
document.getElementById("W3").value=w3;
document.getElementById("W3").innerHTML=w3;
}
function optsW4(){
var w4;
for(i=0;i<arguments.length; i++){
if(document.getElementById(arguments[i]).checked){
w4+="<option>"+arguments[i]+"</option>";
}
}
document.getElementById("W4").value=w4;
document.getElementById("W4").innerHTML=w4;
}
function optsW5(){
var w5;
for(i=0;i<arguments.length; i++){
if(document.getElementById(arguments[i]).checked){
w5+="<option>"+arguments[i]+"</option>";
}
}
document.getElementById("W5").value=w5;
document.getElementById("W5").innerHTML=w5;
}
function checkO1(){
var o1 ="L1";
if(document.getElementById("L1A").checked){
o1 = "L1A";
}
document.getElementById("O1").value=o1;
document.getElementById("O1").innerHTML=o1;
}
function optsO2(){
var o2 ="<option>L2</option>";
if(document.getElementById("L2A").checked){
o2 = "<option>L2A</option>";
}
for(i=0;i<arguments.length; i++){
if(document.getElementById(arguments[i]).checked){
o2+="<option>"+arguments[i]+"</option>";
}
}
document.getElementById("O2").value=o2;
document.getElementById("O2").innerHTML=o2;
}
function optsO3(){
var o3;
if(document.getElementById("MAA").checked){
o3+="<option>MAA</option>";
}else{
for(i=0;i<arguments.length; i++){
if(document.getElementById(arguments[i]).checked){
o3+="<option>"+arguments[i]+"</option>";
}
}
}
document.getElementById("O3").value=o3;
document.getElementById("O3").innerHTML=o3;
}
function optErr(){
var optErrors = 0;
var errorMsg ="Errors <ol>";
if(document.getElementById("W4").value===document.getElementById("W5").value){
optErrors++
errorMsg+="<li>Written 4 and Written 5 are the same</li>"
}
if(document.getElementById("W4").value===document.getElementById("O2").value||document.getElementById("W5").value===document.getElementById("O2").value){
optErrors++
var o2 = document.getElementById("O2").value;
errorMsg+="<li>You can't choose " +o2+ " as a written and oral</li>";
}
if(document.getElementById("W4").value===document.getElementById("O3").value||document.getElementById("W5").value===document.getElementById("O3").value){
optErrors++
var o3 = document.getElementById("O3").value;
errorMsg+="<li>You can't choose " +o3+ " as a written and oral</li>";
}
if(optErrors == 0){
errorMsg="";
document.getElementById("optErrors").innerHTML=errorMsg;
printSubjects("L1", "L2", "MA3", "MA5", "EP", "STS", "GE2", "HI2", "PH2", "CHI", "PHY", "BIO", "HI4", "GE4", "AR4", "MU4", "PH4", "L3", "ECO", "LAT", "L4","ONL", "AGR", "L1A", "L2A", "MAA", "MU2", "AR2", "ICT", "IEC", "SOC", "SCP", "L5", "LBI", "LCH", "LPH","SPO", "DRA","ELE", "ARH");
}
if(optErrors != 0){
errorMsg+="</ol>"
document.getElementById("step3").style.display="none";
document.getElementById("optErrors").innerHTML=errorMsg;
}
}
function checkErrors(NonComp, Total){
var errors = 0;
var errorMsg = "Errors: <ol>";
if(document.getElementById("MA3").checked == false && document.getElementById("MA5").checked == false){
errors++
errorMsg += "<li>You need to choose either MA3 or MA5";
}
if(document.getElementById("MA3").checked == true && document.getElementById("MA5").checked == true){
errors++
errorMsg += "<li>You can't choose both MA3 and MA5";
}
if(document.getElementById("MA3").checked == true && document.getElementById("MAA").checked == true){
errors++
errorMsg += "<li>You can't choose both MA3 and MAA";
}
if(document.getElementById("HI2").checked == true && document.getElementById("HI4").checked == true){
errors++;
errorMsg += "<li>You can't choose both HI2 and HI4.<br>";
}
if(document.getElementById("GE2").checked == true && document.getElementById("GE4").checked == true){
errors++;
errorMsg += "<li>You can't choose both GE2 and GE4.<br>";
}
if(document.getElementById("PH2").checked == true && document.getElementById("PH4").checked == true){
errors++;
errorMsg += "<li> You can't choose both PH2 and PH4.<br>";
}
if(document.getElementById("STS").checked == false && document.getElementById("BIO").checked == false && document.getElementById("CHI").checked == false && document.getElementById("PHY").checked == false){
errors++;
errorMsg += "<li>You need to choose STS or at least one of the 4 period sciences: CHI, PHY or BIO<br>";
}
if(document.getElementById("PH2").checked == false && document.getElementById("PH4").checked == false){
errors++;
errorMsg += "<li>You need to choose either PH2 or PH4.<br>";
}
if(document.getElementById("GE2").checked == false && document.getElementById("GE4").checked == false){
errors++;
errorMsg += "<li>You need to choose either GE2 or GE4.<br>";
}
if(document.getElementById("HI2").checked == false && document.getElementById("HI4").checked == false){
errors++;
errorMsg += "<li>You need to choose either HI2 or HI4.<br>";
}
if(document.getElementById("L1").checked == false){
errors++;
errorMsg += "<li>You need to choose L1.<br>";
}
if(document.getElementById("L2").checked == false){
errors++;
errorMsg += "<li>You need to choose L2.<br>";
}
if(document.getElementById("EP").checked == false){
errorMsg += "<li>You have not chosen EP. This is only possible if you are excused.</li>"
}
if(document.getElementById("L1A").checked == true && document.getElementById("L2A").checked == true
||document.getElementById("L1A").checked == true && document.getElementById("MAA").checked == true
||document.getElementById("L2A").checked == true && document.getElementById("MAA").checked == true){
errors++;
errorMsg += "<li> You can choose only one advanced course.<br>";
}
if(document.getElementById("LBI").checked == true && document.getElementById("LCH").checked == true
||document.getElementById("LBI").checked == true && document.getElementById("LPH").checked == true
||document.getElementById("LCH").checked == true && document.getElementById("LPH").checked == true){
errors++;
errorMsg += "<li> You can choose only one laboratory course.<br>";
}
if(document.getElementById("LBI").checked == true && document.getElementById("BIO").checked == false
||document.getElementById("LPH").checked == true && document.getElementById("PHY").checked == false
||document.getElementById("LCH").checked == true && document.getElementById("CHI").checked == false){
errors++;
errorMsg += "<li> You can't choose laboratory course if you haven't chosen that subject as an option.<br>";
}
if(document.getElementById("MU2").checked == true && document.getElementById("MU4").checked == true){
errors++;
errorMsg += "<li> You can't choose both, MU2 and MU4.<br>";
}
if(document.getElementById("IEC").checked == true && document.getElementById("ECO").checked == true){
errors++;
errorMsg += "<li> You can't choose both, IEC and ECO.<br>";
}
if(document.getElementById("AR2").checked == true && document.getElementById("AR4").checked == true){
errors++;
errorMsg += "<li> You can't choose both, AR2 and AR4.<br>";
}
if(document.getElementById("ONL").checked == true && document.getElementById("ECO").checked == true){
errors++;
errorMsg += "<li> You can't choose both, ECO and ONL.<br>";
}
if(Total < 31){
errors++
errorMsg += "<li> You should have at least 31 periods.<br>";
}
if(NonComp < 29){
errors++
errorMsg += "<li>You need to have at least 29 periods others than complementary courses. You have now "+NonComp+" that kind of periods.";
}
if(errors==0){
if(document.getElementById("EP").checked == false){
errorMsg = "<li>You have not chosen EP. This is only possible if you are excused.</li>"
}else{errorMsg = "";}
if(Total > 35){
errorMsg = "";
}
document.getElementById("step2").style.display="block";
document.getElementById("errors").innerHTML= errorMsg;
addOptions();
}
if(errors!=0){
document.getElementById("step2").style.display="none";
document.getElementById("step3").style.display="none";
document.getElementById("errors").innerHTML= errorMsg;
}
}
/*
function bacOptions(){
for(i=0;i<arguments.length; i++){
if(document.getElementById(arguments[i]).checked && ["CHI", "PHY", "BIO", "HI4", "GE4", "AR4", "MU4", "PH4", "L3", "ECO", "LAT", "L4","ONL", "AGR"].indexOf(document.getElementById(arguments[i]).value)>-1){
listOpts += "<option value='"+arguments[i]+"'> "+arguments[i]+" </option>";
}
}
listOpts+="</select></td></tr>";
listOpts += "<tr><td>Option 5</td><td><select name='Written5' id ='Written5' >";
for(i=0;i<arguments.length; i++){
if(document.getElementById(arguments[i]).checked && ["CHI", "PHY", "BIO", "HI4", "GE4", "AR4", "MU4", "PH4", "L3", "ECO", "LAT", "L4","ONL", "AGR"].indexOf(document.getElementById(arguments[i]).value)>-1){
listOpts += "<option value='"+arguments[i]+"'> "+arguments[i]+" </option>";
}
}
listOpts+="</select></td></tr>\
<tr><td><b>Oral</td><td><b>Subjects</td></tr>\
<tr><td>Option 1</td><td><select name='Oral1' id ='Oral1' >";
if(document.getElementById("L1A").checked){
listOpts += "<option value='L1A'> L1A </option></select></td></tr>";
}else{
listOpts += "<option value='L1A'> L1 </option></select></td></tr>";
}
listOpts+="<tr><td>Option 2</td><td><select name='Oral2' id ='Oral2' >";
if(document.getElementById("L2A").checked){
listOpts += "<option> L2A </option>";
}else{
listOpts += "<option> L2 </option>";
}
for(i=0;i<arguments.length; i++){
if(document.getElementById(arguments[i]).checked && ["GE2", "HI2", "HI4", "GE4"].indexOf(document.getElementById(arguments[i]).value)>-1){
listOpts += "<option value='"+arguments[i]+"'> "+arguments[i]+" </option>";
}
}
listOpts+="</select></td></tr>\
<tr><td>Option 3</td><td><select name='Oral3' id ='Oral3' >";
for(i=0;i<arguments.length; i++){
if(document.getElementById(arguments[i]).checked && ["STS", "PH2", "CHI", "PHY", "BIO", "PH4", "L3", "L4","ONL","MAA"].indexOf(document.getElementById(arguments[i]).value)>-1){
listOpts += "<option value='"+arguments[i]+"'> "+arguments[i]+" </option>";
}
}
listOpts+="</select></td></tr></table></form><br>{{written1}} ";
return listOpts;
}*/
function marks(){
var listMarks="Calculate marks:<br>\
<table>\
<tr><td>Subject</td><td>A</td><td>B</td><td>Written</td><td>Oral</td><td>Final note</td></tr>";
for(i=0;i<arguments.length; i++){
if(document.getElementById(arguments[i]).checked){
if(["L1", "L2", "CHI", "PHY", "BIO", "HI4", "GE4", "AR4", "MU4", "PH4", "L3", "ECO", "LAT", "L4","ONL", "AGR", "L1A", "L2A"].indexOf(document.getElementById(arguments[i]).value)>-1){
listMarks += "<tr><td>"+arguments[i]+":\
</td><td><input type='number' id='"+i+"A' value = 0 min='0' max='10' step='0.1' style='width: 4em;'></td>\
<td><input type='number' id='"+i+"B' value = 0 min='0' max='10' step='0.1' style='width: 4em;'></td>\
</td><td><input type='number' id='"+i+"O' value = 0 min='0' max='10' step='0.1' style='width: 4em;'></td>\
</td><td><input type='number' id='"+i+"W' value = 0 min='0' max='10' step='0.1' style='width: 4em;'></td></tr>";
}
}
}
return listMarks;
}