-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
152 lines (134 loc) · 4.15 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CPI Calculator | By Tanishq</title>
<style>
body {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
font-family: "Century Gothic", sans-serif;
background: linear-gradient(to bottom right, #F8AD9D, #87BFFF);
}
h2 {
margin-bottom: 0;
font-size: 2rem;
color: #2E4F79;
}
p {
margin-top: .25rem;
font-size: 1rem;
color: #555;
}
table {
border-collapse: collapse;
margin-top: .75rem;
width: 80%;
max-width: 600px;
background-color: #fff;
border-radius: 8px;
}
th, td {
padding: .5rem;
border-bottom: 1px solid #ddd;
}
th {
background-color: #3F8EFC;
color: white;
}
input {
width: 90%;
padding: .5rem;
text-align: center;
border: 1px solid #ccc;
border-radius: 4px;
outline: none;
}
input:focus {
border-color: #3F8EFC;
box-shadow: 0 0 5px #3F8EFC;
}
.controls {
margin-top: .25rem;
}
button {
padding: .5rem .75rem;
margin: .5rem;
background-color: #3F8EFC;
color: #fff;
border: none;
border-radius: 5px;
font-size: 1rem;
cursor: pointer;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #2E6FDA;
}
.current-cpi {
margin-top: .5rem;
font-size: 1.5em;
font-weight: bold;
color: #2E4F79;
}
</style>
<script>
const calculateCPI = () => {
const rows = document.querySelectorAll("#subjects-container tr:not(:first-child)");
let totalGrade = 0, totalCredits = 0;
rows.forEach(row => {
const grade = parseFloat(row.querySelector(".grade").value) || 0;
const credits = parseFloat(row.querySelector(".credits").value) || 0;
totalGrade += grade * credits;
totalCredits += credits;
});
document.getElementById("current-cpi").textContent = totalCredits > 0 ? (totalGrade / totalCredits).toFixed(2) : 0;
};
const addSubjectRow = () => {
const table = document.getElementById("subjects-container");
const row = document.createElement("tr");
row.innerHTML = `
<td><input type="text" placeholder="Subject Name"></td>
<td><input type="number" class="grade" oninput="calculateCPI()"></td>
<td><input type="number" class="credits" step="0.5" oninput="calculateCPI()"></td>
`;
table.appendChild(row);
};
const removeSubjectRow = () => {
const table = document.getElementById("subjects-container");
table.deleteRow(-1);
};
window.onload = () => {
addSubjectRow();
document.querySelector("#subjects-container input").focus();
addSubjectRow();
addSubjectRow();
addSubjectRow();
addSubjectRow();
addSubjectRow();
calculateCPI();
};
</script>
</head>
<body>
<h2>CPI Calculator</h2>
<p>Designed for my CPI Calculation needs, might help you too</p>
<table id="subjects-container">
<tr>
<th>Subject Name</th>
<th>Grade</th>
<th>Credits</th>
</tr>
</table>
<div class="controls">
<button onclick="addSubjectRow()">Add Subject</button>
<button onclick="removeSubjectRow()">Remove Subject</button>
</div>
<div class="current-cpi">Current CPI: <span id="current-cpi">0.00</span></div>
</body>
</html>