-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
193 lines (154 loc) · 5.57 KB
/
script.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
let val;
let ar=["none"];
function addBox(){
val=parseInt(document.getElementById("init").value);
if(val==0){
alert("Please select Number of semesters 🙄");
return;
}
else{
document.getElementById("note").removeAttribute("hidden");
document.getElementById("result1").removeAttribute("hidden");
}
const result1 = document.querySelector("#result1");
while(result1.firstChild){
result1.removeChild(result1.firstChild);
}
const h2 = document.createElement("H2");
h2.innerHTML += "Number of Subjects Semester-wise";
result1.appendChild(h2);
for(i=1; i<=val; i++){
const mainDiv = document.createElement("DIV");
const input = document.createElement("INPUT");
input.name = input.id = ("semester"+i);
input.placeholder = "Semester "+i;
input.type = "number";
input.min="2"; input.max="20";
mainDiv.appendChild(input)
result1.appendChild(mainDiv);
}
const btn = document.createElement("BUTTON");
btn.id="proceed-btn";
btn.innerHTML="PROCEED";
btn.onclick = generateGpa;
result1.appendChild(btn);
}
function generateGpa(){
for(i=1; i<=val; i++){
ar[i]=document.getElementById("semester"+i).value;
if(!(ar[i]>=2 && ar[i]<=20)){
alert("Enter atleast 2 & atmost 20 subjects for semester " +i+" 😁");
return;
}
}
if(document.querySelector("#gpaSection")){
document.getElementById("gpaSection").remove();
}
const newSec = document.createElement("SECTION");
newSec.id = "gpaSection";
document.querySelector("#body").appendChild(newSec);
for(i=1; i<=val; i++){
var subjCt=ar[i];
const newDiv = document.createElement("DIV");
newDiv.id = "gpaVals"+ i;
newSec.appendChild(newDiv);
const semLbl = document.createElement("LABEL");
semLbl.innerHTML="Semester "+i+":";
semLbl.style.float="left";
semLbl.style.color="#fff";
semLbl.style.border="3px solid #000";
semLbl.style.backgroundColor="#8c00ff";
semLbl.style.borderRadius="15px";
semLbl.style.margin="20px";
semLbl.style.padding="10px";
newDiv.appendChild(semLbl);
for(j=1; j<=subjCt; j++){
const lineDiv = document.createElement("DIV");
document.getElementById("gpaVals"+i).appendChild(lineDiv);
const subjNo = document.createElement("LABEL");
subjNo.innerHTML="Subject "+j+":";
lineDiv.appendChild(subjNo);
const credit = document.createElement("SELECT");
credit.id = "credit"+i+""+j;
const options = ["O", "A+", "A", "B+", "B", "RA"];
var opVal = 10;
for(pos=0; pos<=5; pos++){
const optElt = document.createElement("OPTION");
optElt.text = options[pos];
optElt.value = opVal--;
credit.appendChild(optElt);
}
lineDiv.appendChild(credit);
const score = document.createElement("INPUT");
score.placeholder = "Credit Value";
score.id="score"+i+""+j;
lineDiv.appendChild(score);
}
}
const btn = document.createElement("BUTTON");
btn.innerHTML="CALCULATE";
btn.id="calc-btn";
btn.onclick = calcRes;
newSec.appendChild(btn);
}
resArr=["none"];
function calcRes(){
for(i=1; i<=val; i++){
var subjCt = ar[i];
res=0;
totalCredit=0;
for(j=1; j<=subjCt; j++){
var grade = parseInt(document.getElementById("credit"+i+""+j).value);
var point = parseFloat(document.getElementById("score"+i+""+j).value);
console.log(grade+" "+point);
if(isNaN(point)){
alert("Enter all data properly !!! 😖");
return;
}
if(grade!=5){
res+=grade*(1.0)*point;
totalCredit+=point;
}else{
alert("It seems You've an arrear in Semester "+i+" So, you are ineligible for CGPA Calculation 😬");
prompt("Do you like this CGPA Cal-C 🤩",);
return;
}
}
console.log(res+" "+totalCredit);
resArr[i]=res/totalCredit;
}
console.log(resArr)
for(i=1; i<=val; i++){
const eleExist = document.getElementById("dispLabl"+i);
if(!(eleExist)){
const gpaDiv = document.getElementById("gpaVals"+i);
const lbl = document.createElement("LABEL");
lbl.id = "dispLabl"+i;
lbl.className = "dispLbl";
lbl.innerHTML = parseFloat(resArr[i]).toFixed(3);
gpaDiv.appendChild(lbl);
}
else{
eleExist.innerHTML = parseFloat(resArr[i]).toFixed(3);
}
}
finRes=0;
for(i=1; i<=val; i++){
finRes+=(resArr[i]);
}
finRes=finRes/val;
console.log(finRes.toFixed(3));
const finDiv = document.querySelector("#finDiv");
if(finDiv){
finDiv.innerHTML = "Your CGPA: " + finRes.toFixed(3);
}
else{
document.getElementById("gpaSection").appendChild(document.createElement("HR"));
const finDiv = document.createElement("LABEL");
document.getElementById("gpaSection").appendChild(finDiv);
finDiv.id = "finDiv";
finDiv.innerHTML ="Your CGPA: " + finRes.toFixed(3);
document.getElementById("gpaSection").appendChild(document.createElement("HR"));
}
return;
}