-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
89 lines (77 loc) · 3.01 KB
/
Copy pathscript.js
File metadata and controls
89 lines (77 loc) · 3.01 KB
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
const addBtn = document.getElementById("addBtn");
const clearBtn = document.getElementById("clearBtn");
const subjectList = document.getElementById("subjectList");
// Load saved data on page load
let subjects = JSON.parse(localStorage.getItem("subjects")) || [];
renderSubjects();
addBtn.addEventListener("click", () => {
const subject = document.getElementById("subject").value.trim();
const total = parseFloat(document.getElementById("total").value);
const attended = parseFloat(document.getElementById("attended").value);
if (!subject || isNaN(total) || isNaN(attended) || attended > total || total <= 0) {
alert("⚠️ Please enter valid values.");
return;
}
const percent = (attended / total) * 100;
let status = "";
let extraInfo = "";
if (percent >= 75) {
const canSkip = Math.floor(attended / 0.75 - total);
status = `<span class='eligible'>✅ Eligible</span>`;
extraInfo = `You can skip ${canSkip} more class(es).`;
} else {
const needToAttend = Math.ceil(0.75 * total - attended);
status = `<span class='not-eligible'>❌ Not Eligible</span>`;
extraInfo = `Attend ${needToAttend} more class(es) to reach 75%.`;
}
// 🌟 SMART INSIGHT FEATURE 🌟
let insight = "";
if (percent >= 90) {
insight = "🌟 Excellent! Keep up the streak 🎯";
} else if (percent >= 75) {
insight = "💪 Great! Stay consistent and maintain your pace.";
} else if (percent >= 60) {
insight = "📈 You're close — attend a few more classes to reach 75%.";
} else {
insight = "🚀 Time to focus — attend regularly to improve!";
}
const record = { subject, total, attended, percent: percent.toFixed(2), status, extraInfo, insight };
subjects.push(record);
localStorage.setItem("subjects", JSON.stringify(subjects));
renderSubjects();
document.getElementById("subject").value = "";
document.getElementById("total").value = "";
document.getElementById("attended").value = "";
});
function renderSubjects() {
subjectList.innerHTML = "";
if (subjects.length === 0) {
subjectList.innerHTML = "<p>No records yet.</p>";
return;
}
subjects.forEach((s, index) => {
const card = document.createElement("div");
card.classList.add("subject-card");
card.innerHTML = `
<h3>${s.subject}</h3>
<p>📘 Attendance: <b>${s.percent}%</b></p>
<p>${s.status}</p>
<p>${s.extraInfo}</p>
<p style="font-style: italic; color: #6a1b9a;">${s.insight}</p>
<button onclick="deleteSubject(${index})" style="background:#ffd6a5; color:#333;">🗑 Remove</button>
`;
subjectList.appendChild(card);
});
}
function deleteSubject(index) {
subjects.splice(index, 1);
localStorage.setItem("subjects", JSON.stringify(subjects));
renderSubjects();
}
clearBtn.addEventListener("click", () => {
if (confirm("Are you sure you want to clear all history?")) {
subjects = [];
localStorage.removeItem("subjects");
renderSubjects();
}
});