-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain2.js
More file actions
80 lines (72 loc) · 2.99 KB
/
Copy pathmain2.js
File metadata and controls
80 lines (72 loc) · 2.99 KB
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
const add=document.querySelector('#add');
const courseCode=document.querySelector('#courseCode');
const unitValue=document.querySelector('#unitValue');
const grade=document.querySelector('#grade');
const tBody=document.querySelector('#tbody');
const table=document.querySelector('#table');
const tfoot=document.querySelector('#tfoot');
const calcGp=document.querySelector('#calcGp');
const reset=document.querySelector('#reset');
const fourPoint=document.querySelector('#fourPoint');
let gpArray=[];
add.addEventListener('click', () => {
if(courseCode.value=== '' || unitValue.value <= 0 || grade.selectedIndex===0) {
alert('Wrong/No input, check and try again')
} else {
const tr= document.createElement('tr');
const tdCourseCode=document.createElement('td');
tdCourseCode.innerHTML=courseCode.value;
const tdUnitValue=document.createElement('td');
tdUnitValue.innerHTML=unitValue.value;
const tdGrade=document.createElement('td');
tdGrade.innerHTML=grade.options[grade.selectedIndex].text;
tr.appendChild(tdCourseCode);
tr.appendChild(tdUnitValue);
tr.appendChild(tdGrade);
tBody.appendChild(tr);
table.classList.remove('display-none');
calcGp.classList.remove('display-none');
reset.classList.remove('display-none');
gpArray.push({'unitValue':unitValue.value, 'grade':grade.options[grade.selectedIndex].value});
courseCode.value='';
unitValue.value='';
grade.selectedIndex='0';
}
} )
calcGp.addEventListener('click', () => {
let unitValues = 0, productOfUnitValuesAndGrades=0,
sumOfProductOfUnitValuesAndGrades=0;
gpArray.forEach(result=> {
unitValues += parseInt(result.unitValue);
productOfUnitValuesAndGrades = parseInt(result.unitValue) * parseInt(result.grade);
sumOfProductOfUnitValuesAndGrades += productOfUnitValuesAndGrades;
});
const tr=document.createElement('tr');
tdTotalUnitValue=document.createElement('td');
tdTotalUnitValue.innerHTML=`Total Units: ${unitValues}`;
tdGpa=document.createElement('td');
tdGpa.setAttribute('colspan', '2');
tdGpa.innerHTML=`GP: ${(sumOfProductOfUnitValuesAndGrades / unitValues).toFixed(2)}`;
tr.appendChild(tdTotalUnitValue);
tr.appendChild(tdGpa);
if(tfoot.querySelector('tr') !== null){
tfoot.querySelector('tr').remove();
}
tfoot.appendChild(tr);
});
reset.addEventListener('click', () => {
gpArray=[];
tBody.querySelectorAll('*').forEach(child=> child.remove());
if(tfoot.querySelector('tr') !== null){
tfoot.querySelector('tr').remove();
}
table.classList.add('display-none');
calcGp.classList.add('display-none');
reset.classList.add('display-none');
})
fourPoint.addEventListener('click', () => {
window.location.href = "index.html";
})
ourName.addEventListener('click', ()=>{
alert('Oyerinde Sodiq, Abdulyekeen Oluwadabira, Abubakar Yetunde, Olurode Musab, Dauda Shedrack, Ademiju Paul, Bassey Shalom, Elamah Semiat, Alikeh Christoper')
})