-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
193 lines (174 loc) · 5.98 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
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css" />
<title>SGPA Calculator</title>
</head>
<body>
<div class="main">
<div class="navbar">
<h1 class="title">
<div class="logo">
<a href="https://github.com/AnanthaTeja"><img src="AT3.jpeg" alt="DANT" /></a>
</div>
<p name="ti">SGPA / CGPA <span>Calculator</span></p>
</h1>
</div>
<table id="sgpaTable">
<tr>
<th>Subject</th>
<th>Credits</th>
<th>Grade Points</th>
</tr>
<tr>
<td>
<input type="text" name="subject[]" placeholder="Enter subject" />
</td>
<td>
<input type="number" name="credits[]" placeholder="Enter credits" oninput="javascript: if (this.value.length > 1) this.value = this.value.slice(0, 1);" />
</td>
<td>
<select name="gradePoints[]">
<option value="">Choose grade</option>
<option value="10">O</option>
<option value="9">A+</option>
<option value="8">A</option>
<option value="7">B+</option>
<option value="6">B</option>
<option value="5">C+</option>
<option value="4">C</option>
<option value="3">D+</option>
<option value="2">D</option>
<!-- Add more grade options if needed -->
</select>
</td>
</tr>
</table>
<div class="in">
<b>Number of Subjects : </b>
<input id="inp" type="number" name="subs" placeholder="Enter number of subjects" oninput="javascript: if (this.value.length > 2) this.value = this.value.slice(0, 2);" />
</div>
<p class="grades">
<br />
<button id="addButton">Add</button>
<button id="calculateButton">Calculate SGPA/CGPA</button>
<table id="grade">
<tr>
<th>Grade</th>
<th>Score</th>
</tr>
<tr>
<td>O</td>
<td>10</td>
</tr>
<tr>
<td>A+</td>
<td>9</td>
</tr>
<tr>
<td>A</td>
<td>8</td>
</tr>
<tr>
<td>B+</td>
<td>7</td>
</tr>
<tr>
<td>B</td>
<td>6</td>
</tr>
<tr>
<td>C+</td>
<td>5</td>
</tr>
<tr>
<td>C</td>
<td>4</td>
</tr>
</table>
</p>
<div id="result"></div>
<script>
document
.getElementById("addButton")
.addEventListener("click", function () {
var table = document.getElementById("sgpaTable");
var numSubjects = parseInt(document.getElementById("inp").value);
if(numSubjects==0){
numSubjects=2;
}
document.getElementById("inp").addEventListener("input", function() {
location.reload();
});
for (var i = 0; i < numSubjects-1; i++) {
var row = table.insertRow(table.rows.length); // Insert before the last row
var subjectCell = row.insertCell(0);
var creditsCell = row.insertCell(1);
var gradePointsCell = row.insertCell(2);
subjectCell.innerHTML =
'<input type="text" name="subject[]" placeholder="Enter subject">';
creditsCell.innerHTML =
'<input type="number" name="credits[]" placeholder="Enter credits">';
gradePointsCell.innerHTML =
`<select name="gradePoints[]">
<option value="">Choose grade</option>
<option value="10">O</option>
<option value="9">A+</option>
<option value="8">A</option>
<option value="7">B+</option>
<option value="6">B</option>
<option value="5">C+</option>
<option value="4">C</option>
<option value="3">D+</option>
<option value="2">D</option>
</select>`;
}
});
document
.getElementById("calculateButton")
.addEventListener("click", function () {
var table = document.getElementById("sgpaTable");
var subjects = table.querySelectorAll('input[name="subject[]"]');
var credits = table.querySelectorAll('input[name="credits[]"]');
var gradePoints = table.querySelectorAll('select[name="gradePoints[]"]');
var courseCredits = [];
var courseGrades = [];
for (var i = 0; i < subjects.length; i++) {
courseCredits.push(parseInt(credits[i].value));
courseGrades.push(gradePoints[i].value);
}
// Perform the SGPA calculation using the Java code here
var sgpa = Java.performSGPA(courseCredits, courseGrades);
// Display the result
var resultDiv = document.getElementById("result");
resultDiv.innerHTML = "SGPA: <strong>" + sgpa + "</strong>";
});
</script>
<script>
var Java = {
performSGPA: function (credits, grades) {
var gradePoints = {
"10": 10,
"9": 9,
"8": 8,
"7": 7,
"6": 6,
"5": 5,
"4": 4,
"3":3,
"2":2,
};
var totalGradePoints = 0;
var totalCredits = 0;
for (var i = 0; i < credits.length; i++) {
totalGradePoints += credits[i] * gradePoints[grades[i]];
totalCredits += credits[i];
}
var sgpa = totalGradePoints / totalCredits;
return sgpa;
},
};
</script>
</div>
</body>
</html>