-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
82 lines (70 loc) · 2.09 KB
/
Copy pathscript.js
File metadata and controls
82 lines (70 loc) · 2.09 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
// ===== PAGE NAVIGATION =====
const pages = document.querySelectorAll(".page");
const cards = document.querySelectorAll(".card");
const backButtons = document.querySelectorAll(".back");
function showPage(id) {
pages.forEach(page => page.classList.remove("active"));
document.getElementById(id).classList.add("active");
}
// Card click
cards.forEach(card => {
card.addEventListener("click", () => {
const task = card.getAttribute("data-task");
showPage(task);
});
});
// Back button
backButtons.forEach(btn => {
btn.addEventListener("click", () => {
showPage("home");
});
});
// ===== TASK 1: COUNTER =====
let count = 0;
const countDisplay = document.getElementById("count");
function updateCounter() {
countDisplay.innerText = count;
if (count < 0) {
countDisplay.style.color = "red";
} else {
countDisplay.style.color = "green";
}
}
document.getElementById("inc").addEventListener("click", () => {
count++;
updateCounter();
});
document.getElementById("dec").addEventListener("click", () => {
count--;
updateCounter();
});
document.getElementById("reset").addEventListener("click", () => {
count = 0;
updateCounter();
});
// ===== TASK 2: TEXT EDITOR =====
document.getElementById("updateText").addEventListener("click", () => {
const value = document.getElementById("textInput").value;
const para = document.getElementById("displayText");
if (value === "") {
alert("Please enter text");
} else {
para.innerText = value;
}
});
// ===== TASK 3: THEME TOGGLE =====
let darkMode = false;
const themeBtn = document.getElementById("themeBtn");
themeBtn.addEventListener("click", () => {
if (!darkMode) {
document.body.style.backgroundColor = "#111";
document.body.style.color = "white";
themeBtn.innerText = "Switch to Light Mode";
darkMode = true;
} else {
document.body.style.backgroundColor = "#e6f7ff";
document.body.style.color = "black";
themeBtn.innerText = "Switch to Dark Mode";
darkMode = false;
}
});