-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
83 lines (70 loc) · 2.17 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
// Input references
let container = document.querySelector(".container");
let result = document.querySelector(".result");
let maths = document.querySelector("#maths");
let phy = document.querySelector("#phy");
let che = document.querySelector("#che");
let eng = document.querySelector("#eng");
let hindi = document.querySelector("#hindi");
let btn = document.querySelector(".btn");
let form = document.querySelector(".input");
function allCalculation() {
let total =
parseFloat(maths.value) +
parseFloat(phy.value) +
parseFloat(che.value) +
parseFloat(eng.value) +
parseFloat(hindi.value);
let percentage = (total * 100) / 500;
let Grades;
if (percentage <= 100 && percentage >= 80) {
Grades = "A";
}
if (percentage <= 79 && percentage >= 60) {
Grades = "B";
}
if (percentage <= 59 && percentage >= 33) {
Grades = "C";
}
if (percentage <= 32 && percentage >= 0) {
Grades = "F";
}
if (Grades === "A" || Grades === "B" || Grades === "C") {
Status = "Pass";
} else if (Grades === "F") {
Status = "Fail";
} else {
Status = "Please Enter Valid Marks";
}
function showResult() {
result.innerHTML = "";
let output = document.createElement("div");
output.setAttribute("class", "output");
let p1 = document.createElement("p");
let p2 = document.createElement("p");
let p3 = document.createElement("p");
let p4 = document.createElement("p");
p1.textContent =
total > 500 || typeof total !== "number"
? ``
: ` Total Score : ${total}/500`;
p2.textContent =
percentage > 100 || typeof percentage !== "number"
? ``
: ` Percentage : ${percentage}`;
p3.textContent = Grades === undefined ? `` : ` Grade : ${Grades}`;
p4.textContent =
Status === "A" || Status === "B" || Status === "C" || Status === "F"
? ` You are ${Status}`
: `${Status}`;
output.append(p1);
output.append(p2);
output.append(p3);
output.append(p4);
result.append(output);
}
return showResult();
}
btn.addEventListener("click", () => {
allCalculation();
});