-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
77 lines (71 loc) · 2.68 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
const form = document.querySelector("form");
const inputs = document.querySelectorAll(".form-control");
const calculate_btn = document.querySelector("#calculate");
let gpa_s = [];
let module_data = [];
$.getJSON("https://muksithmra.github.io/NIBM-GPA-Calculator/module_data.json", function (data, textStatus, jqXHR) {
module_data = data;
});
calculate_btn.addEventListener("click", function () {
gpa_s = [];
inputs.forEach((element) => {
if (element.value == "" || element.value > 4.0 || element.value < 0.0) {
element.classList.add("is-invalid");
element.focus();
} else {
element.classList.remove("is-invalid");
gpa_s.push(element.value);
}
});
if (gpa_s.length == inputs.length) {
$("#result-modal").modal("show");
$("#result-modal .modal-body #final-GPA").text(
calculateFinalGpa().toFixed(2)
);
}
});
function calculateFinalGpa() {
let tot_up = 0;
let tot_credit = 0;
for (let index = 0; index < gpa_s.length; index++) {
tot_credit += module_data[index].credit;
tot_up += gpa_s[index] * module_data[index].credit;
}
if (tot_up > 0) {
final_gpa = tot_up / tot_credit;
if (final_gpa >= 3.8) {
$("#result-modal .modal-body img").attr("src", "https://muksithmra.github.io/NIBM-GPA-Calculator/img/distinction.jpg");
$("#result-modal .modal-body #grade").text("Distinction");
$("#result-modal .modal-body #grade").removeClass("text-danger");
$("#result-modal .modal-body #grade").addClass("text-success");
$("#result-modal .modal-body #motivation").text(
"You are the Best , Well Done !"
);
} else if (final_gpa >= 3.3) {
$("#result-modal .modal-body img").attr("src", "https://muksithmra.github.io/NIBM-GPA-Calculator/img/pass.jpg");
$("#result-modal .modal-body #grade").text("Pass");
$("#result-modal .modal-body #grade").removeClass("text-danger");
$("#result-modal .modal-body #grade").addClass("text-success");
$("#result-modal .modal-body #motivation").text(
"Congratulation Work More Hard !"
);
} else {
$("#result-modal .modal-body img").attr("src", "https://muksithmra.github.io/NIBM-GPA-Calculator/img/fail.jpg");
$("#result-modal .modal-body #grade").text("Fail");
$("#result-modal .modal-body #grade").removeClass("text-success");
$("#result-modal .modal-body #grade").addClass("text-danger");
$("#result-modal .modal-body #motivation").text(
"It's Ok , Let's Try again !"
);
}
return final_gpa;
}
return 0;
}
$("#clearBtn").click(function (e) {
e.preventDefault();
inputs.forEach((element) => {
element.value = "";
element.classList.remove("is-invalid");
});
});