-
Notifications
You must be signed in to change notification settings - Fork 0
/
js.js
223 lines (202 loc) · 9.53 KB
/
js.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
document.addEventListener("DOMContentLoaded", function () {
const inputFields = document.getElementById("input-fields");
const resultsDiv = document.getElementById("results");
// Function to navigate to a new page
function navigateToPage(page) {
window.location.href = page;
}
// Function to toggle the side menu
function toggleMenu() {
const sideMenu = document.getElementById('side-menu');
const overlay = document.querySelector('.overlay');
const content = document.querySelector('.content');
if (sideMenu.style.left === '0px') {
sideMenu.style.left = '-250px';
overlay.style.filter = 'brightness(100%)';
content.style.filter = 'brightness(100%)';
} else {
sideMenu.style.left = '0px';
overlay.style.filter = 'brightness(60%)';
content.style.filter = 'brightness(60%)';
}
}
document.addEventListener('click', function (event) {
const sideMenu = document.getElementById('side-menu');
const menuToggle = document.getElementById('menu-toggle');
if (sideMenu && menuToggle && !menuToggle.contains(event.target) && !sideMenu.contains(event.target)) {
sideMenu.style.left = '-250px';
}
});
// Expose functions to global scope
window.toggleMenu = toggleMenu;
window.navigateToPage = navigateToPage;
// Add event listener to the home button
const homeButton = document.getElementById("home-button");
if (homeButton) {
homeButton.addEventListener("click", function () {
navigateToPage("index.html");
});
}
// Helper function to get URL parameters
function getQueryParams() {
const urlParams = new URLSearchParams(window.location.search);
return {
regulation: urlParams.get('regulation'),
course: urlParams.get('course')
};
}
// Handle input fields display based on URL parameters
function handleInputFields() {
const params = getQueryParams();
if (params.regulation === '2018') {
if (params.course === 'theory') {
inputFields.innerHTML = `
<label for="ct1">Cycle Test 1 (25 Marks):</label>
<input type="number" id="ct1" max="25" min="0" required>
<label for="ct2">Cycle Test 2 (50 Marks):</label>
<input type="number" id="ct2" max="50" min="0" required>
<label for="ct3">Cycle Test 3 (50 Marks):</label>
<input type="number" id="ct3" max="50" min="0" required>
<label for="ct4">Cycle Test 4 (10 Marks):</label>
<input type="number" id="ct4" max="10" min="0" required>
`;
} else if (params.course === 'joint') {
inputFields.innerHTML = `
<p>To know how to calculate marks to percentage, click <a href="howtouse.html">here</a></p>
<label for="ct1">Cycle Test 1 (10%):</label>
<input type="number" id="ct1" max="10" min="0" required>
<label for="ct2">Cycle Test 2 (15%):</label>
<input type="number" id="ct2" max="15" min="0" required>
<label for="ct3">Cycle Test 3 (15%):</label>
<input type="number" id="ct3" max="15" min="0" required>
<label for="ct4">Cycle Test 4 (10%):</label>
<input type="number" id="ct4" max="10" min="0" required>
<label for="practical-lab">Lab Practical (25%):</label>
<input type="number" id="practical-lab" max="25" min="0" required>
`;
}
} else if (params.regulation === '2021') {
if (params.course === 'theory') {
inputFields.innerHTML = `
<label for="ct1">Cycle Test 1 (50 Marks):</label>
<input type="number" id="ct1" max="50" min="0" required>
<label for="ct2">Cycle Test 2 (50 Marks):</label>
<input type="number" id="ct2" max="50" min="0" required>
`;
} else if (params.course === 'joint') {
inputFields.innerHTML = `
<p>To know how to calculate marks to percentage, click <a href="howtouse.html">here</a></p>
<label for="ct1">Cycle Test 1 (30%):</label>
<input type="number" id="ct1" max="30" min="0" required>
<label for="ct2">Cycle Test 2 (30%):</label>
<input type="number" id="ct2" max="30" min="0" required>
<label for="practical">Practical (40%):</label>
<input type="number" id="practical" max="40" min="0" required>
`;
}
}
}
// Function to validate inputs
function validateInputs(inputs) {
for (let i = 0; i < inputs.length; i++) {
const value = parseFloat(inputs[i].value);
if (isNaN(value) || value < 0 || value > parseFloat(inputs[i].max)) {
return false;
}
}
return true;
}
// Function to scroll to results section
function scrollToResults() {
resultsDiv.scrollIntoView({ behavior: "smooth" });
}
// Calculate marks function
window.calculateMarks = function () {
const params = getQueryParams();
let totalInternal = 0;
const inputs = document.querySelectorAll('#input-fields input');
if (!validateInputs(inputs)) {
resultsDiv.innerHTML = "<p>Please enter valid values for all fields.</p>";
resultsDiv.style.display = "block";
scrollToResults();
return;
}
if (params.regulation === '2018' && params.course === 'theory') {
const ct1 = parseFloat(document.getElementById('ct1').value) || 0;
const ct2 = parseFloat(document.getElementById('ct2').value) || 0;
const ct3 = parseFloat(document.getElementById('ct3').value) || 0;
const ct4 = parseFloat(document.getElementById('ct4').value) || 0;
totalInternal = (ct1 / 2.5) + (ct2 / 3.333333333333333) + (ct3 / 3.333333333333333) + ct4;
} else if (params.regulation === '2021' && params.course === 'theory') {
const ct1 = parseFloat(document.getElementById('ct1').value) || 0;
const ct2 = parseFloat(document.getElementById('ct2').value) || 0;
totalInternal = ct1 + (ct2 / 5);
} else {
inputs.forEach(input => {
totalInternal += parseFloat(input.value) || 0;
});
}
const grades = [
{ grade: 'O', marks: 91 },
{ grade: 'A+', marks: 81 },
{ grade: 'A', marks: 71 },
{ grade: 'B+', marks: 61 },
{ grade: 'B', marks: 56 },
{ grade: 'C', marks: 50 },
];
let resultHTML = `
<h2>Results</h2>
<p>Total Internal Marks: ${totalInternal.toFixed(2)}</p>
`;
if (params.regulation === '2018') {
const weightage = params.course === 'theory' ? 2 : 4;
grades.forEach(grade => {
const requiredMarks = (grade.marks - totalInternal) * weightage;
if (requiredMarks > 0) {
if (requiredMarks > 100) {
resultHTML += `<p>Required External Marks for ${grade.grade} Grade: Not possible</p>`;
} else {
resultHTML += `<p>Required External Marks for ${grade.grade} Grade: ${requiredMarks.toFixed(2)}</p>`;
}
}
});
} else if (params.regulation === '2021') {
const weightage = params.course === 'theory' ? 2 : 1;
if (params.course === 'theory') {
grades.forEach(grade => {
const requiredMarks = (grade.marks - totalInternal) * weightage;
if (requiredMarks > 0) {
if (requiredMarks > 100) {
resultHTML += `<p>Required Marks for ${grade.grade} Grade: Not possible</p>`;
} else {
resultHTML += `<p>Required Marks for ${grade.grade} Grade: ${requiredMarks.toFixed(2)}</p>`;
}
}
});
} else {
let gradeObtained = 'F';
if (totalInternal >= 91) {
gradeObtained = 'O';
} else if (totalInternal >= 81) {
gradeObtained = 'A+';
} else if (totalInternal >= 71) {
gradeObtained = 'A';
} else if (totalInternal >= 61) {
gradeObtained = 'B+';
} else if (totalInternal >= 56) {
gradeObtained = 'B';
} else if (totalInternal >= 50) {
gradeObtained = 'C';
}
resultHTML += `<p>Your Grade: ${gradeObtained}</p>`;
}
}
resultsDiv.innerHTML = resultHTML;
resultsDiv.style.display = "block";
scrollToResults();
};
// Initialize the input fields based on the current page
if (inputFields) {
handleInputFields();
}
});