-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
55 lines (45 loc) · 1.61 KB
/
Copy pathscript.js
File metadata and controls
55 lines (45 loc) · 1.61 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
let birthdays = JSON.parse(localStorage.getItem("birthdays")) || [];
function saveBirthdays() {
localStorage.setItem("birthdays", JSON.stringify(birthdays));
}
function addBirthday() {
const nameInput = document.getElementById("name-input").value;
const dateInput = document.getElementById("date-input").value;
if (nameInput && dateInput) {
birthdays.push({ name: nameInput, date: dateInput });
saveBirthdays();
displayBirthdays();
document.getElementById("name-input").value = "";
document.getElementById("date-input").value = "";
}
}
function removeBirthday(index) {
birthdays.splice(index, 1);
saveBirthdays();
displayBirthdays();
}
function displayBirthdays() {
const container = document.getElementById("birthday-container");
container.innerHTML = "";
if (birthdays.length > 0) {
birthdays.forEach((bday, index) => {
const card = document.createElement("div");
card.className = "birthday-card";
card.innerHTML = `
<span>${bday.name} - ${bday.date}</span>
<button onclick="removeBirthday(${index})">×</button>
`;
container.appendChild(card);
});
} else {
container.innerHTML = "<p class='empty'>No birthdays yet.</p>";
}
}
// Highlight active navigation link
document.querySelectorAll('.nav-link').forEach(link => {
link.addEventListener('click', function() {
document.querySelectorAll('.nav-link').forEach(nav => nav.classList.remove('active'));
this.classList.add('active');
});
});
displayBirthdays();