-
Notifications
You must be signed in to change notification settings - Fork 21
/
index.html
224 lines (205 loc) · 6.4 KB
/
index.html
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
<head>
<link
href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css"
rel="stylesheet"
/>
</head>
<body>
<div class="p-12">
Input your previous sem gpa:
<input type="text" id="prev-gpa" class="rounded p-2 border-2" placeholder="6.9" />
<br />
input the class interval (Marks range for each grade): <input type="number" class="rounded p-2 border-2" id="class-interval" value="10" placeholder="10"/>
<br/>
Include LAB?<br />
<label class="switch">
<input type="checkbox" id="labs" onchange="displayLabOutput(this)" />
<span class="slider round"></span>
</label>
<br />
<br/>
<hr />
<br />
<div id="main-marks"></div>
<div id="lab-marks"></div>
<br />
<hr />
<br />
<button onclick="computeGPA()" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">GET MY GPA BICH</button>
<h1 id="output"></h1>
</div>
<script>
let subjects = ["ELECTIVE_1", "ELECTIVE_2", "CC", "OOAD", "CD"];
let nonsubjects = ["CC_LAB", "OOAD_LAB"];
let toggle = document.getElementById("lab-marks");
window.addEventListener("load", displayOutput);
function computeGPA() {
var prevgpa = parseFloat(document.getElementById("prev-gpa").value),
subjects = document.querySelectorAll(".mark"),
outof = document.querySelectorAll(".outof"),
credits = document.querySelectorAll(".credits"),
nonsubjects = document.querySelectorAll(".lab-mark"),
laboutof = document.querySelectorAll(".lab-outof"),
n = subjects.length,
m = nonsubjects.length;
outof = Object.keys(outof).map((outo) => parseFloat(outof[outo].value));
subjects = Object.keys(subjects).map((outo) =>
parseFloat(subjects[outo].value)
);
credits = Object.keys(credits).map((outo) =>
parseFloat(credits[outo].value)
);
nonsubjects = Object.keys(nonsubjects).map((outo) =>
parseFloat(nonsubjects[outo].value)
);
laboutof = Object.keys(laboutof).map((outo) =>
parseFloat(laboutof[outo].value)
);
let marks = [];
for (var i = 0; i < n; i++) {
if (i % 2 == 0) {
let x = (subjects[i] / outof[i]) * 0.15;
marks.push(x);
console.log("EVENT", marks);
} else {
let x = (subjects[i] / outof[i]) * 0.85;
marks[marks.length - 1] += x;
console.log("odd", marks);
}
}
for (var i = 0; i < m; i++) {
let x = nonsubjects[i] / laboutof[i];
marks.push(x);
}
marks = marks.map(mark => mark*100);
console.log("HELLO",marks);
finalmarks = []
let top_ci = 100
var ci = parseInt(document.getElementById("class-interval").value)
for (var i=0;i<credits.length;i++){
if (marks[i] > top_ci-ci){
marks[i] = 10;
} else if(marks[i] > top_ci-(2*ci)){
marks[i]= 9;
} else if(marks[i] > top_ci-(3*ci)) {
marks[i]= 8;
} else if(marks[i] > top_ci-(4*ci)){
marks[i]= 7;
} else if(marks[i] > top_ci-(5*ci)){
marks[i]= 5;
} else if(marks[i] > top_ci-(6*ci)) {
marks[i]= 4;
} else{
marks[i]=0;
}
marks[i] *= credits[i];
}
console.log(marks);
let markSum = 0;
let creditsSum = 0;
for (var i = 0; i < credits.length; i++) {
markSum += marks[i];
creditsSum += credits[i];
}
console.log(markSum, creditsSum);
let finalMarks = markSum / creditsSum;
finalMarks = finalMarks * 0.5 + prevgpa * 0.5;
console.log(finalMarks);
let outputd = document.getElementById("output");
outputd.innerHTML = "<p class='2xl-text'>✨ " +finalMarks + " ✨</p>";
}
function displayOutput() {
outputdiv = document.getElementById("main-marks");
output = "";
subjects.forEach(
(lab) =>
(output += `
<div class="p-8 border-4">
<h2 class="text-2xl bold">
${lab}
</h2>
assignment: <input type="number" class="mark rounded p-2 border-2" placeholder="6.9" /> out of <input type="number" class="outof rounded p-2 border-2" placeholder="10" value="10" /><br/>
<br/>isa: <input type="number" class="mark rounded p-2 border-2" placeholder="6.9" /> out of <input type="number" class="outof rounded p-2 border-2" placeholder="10" value="10" /><br/>
<br/>credits: <input type="number" class="credits rounded p-2 border-2" placeholder="4.20" value="4" /><br/>
</div>
`)
);
outputdiv.innerHTML = output;
}
function displayLabOutput(e) {
outputdiv = document.getElementById("lab-marks");
if (e.checked) {
output = "";
nonsubjects.forEach(
(lab) =>
(output += `
<div class="p-8 border-4">
<h2 class="text-2xl">
${lab}
</h2>
marks: <input type="number" class="lab-mark rounded p-2 border-2" placeholder="6.9" /> out of <input type="number" class="lab-outof focus:outline-none focus:ring focus:border-blue-300" placeholder="10" /><br/>
<br/>credits: <input type="number" class="credits rounded p-2 border-2" placeholder="4.20" value="1" /><br/>
</div>`)
);
outputdiv.innerHTML = output;
} else {
outputdiv.innerHTML = "";
}
}
function calculateCGPA() {}
</script>
<style>
.switch {
position: relative;
display: inline-block;
width: 60px;
height: 20px;
}
/* Hide default HTML checkbox */
.switch input {
opacity: 0;
width: 0;
height: 0;
}
/* The slider */
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
-webkit-transition: .4s;
transition: .4s;
}
.slider:before {
position: absolute;
content: "";
height: 20px;
width: 20px;
left: 2px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
}
input:checked + .slider {
background: linear-gradient(to right, red, orange , yellow, rgb(43, 231, 43), blue, rgb(114, 54, 114));
}
input:focus + .slider {
box-shadow: 0 0 1px #000000;
}
input:checked + .slider:before {
-webkit-transform: translateX(38px);
-ms-transform: translateX(38px);
transform: translateX(38px);
}
/* Rounded sliders */
.slider.round {
border-radius: 34px;
}
.slider.round:before {
border-radius: 50%;
}
</style>
</body>