Skip to content

Commit 429d850

Browse files
committed
feat: day 19
1 parent cadc870 commit 429d850

File tree

4 files changed

+74
-8
lines changed

4 files changed

+74
-8
lines changed

019-theme clock/index.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,20 @@
33
<head>
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<link
7+
rel="stylesheet"
8+
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css"
9+
integrity="sha512-+4zCK9k+qNFUR5X+cKL9EIR+ZOhtIloNl9GIKS57V1MyNsYpYcUrUeQc9vNfzsWfV28IaLL3i96P9sdNyeRssA=="
10+
crossorigin="anonymous"
11+
/>
612
<link rel="stylesheet" href="style.css" />
713
<title>Theme Clock</title>
814
</head>
915
<body>
1016
<button class="toggle">Dark mode</button>
17+
<button class="sound-toggle">
18+
<i class="fas fa-volume-mute"></i>
19+
</button>
1120
<div class="clock-container">
1221
<div class="clock">
1322
<div class="needle hour"></div>
@@ -18,6 +27,8 @@
1827
<div class="time"></div>
1928
<div class="date"></div>
2029
</div>
30+
<!-- Add a Ticking Sound -->
31+
<audio class="tick-sound" src="sounds/tick.mp3"></audio>
2132
<script src="script.js"></script>
2233
</body>
2334
</html>

019-theme clock/script.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ const secondElement = document.querySelector(".second");
44
const timeElement = document.querySelector(".time");
55
const dateElement = document.querySelector(".date");
66
const toggle = document.querySelector(".toggle");
7+
const soundToggle = document.querySelector(".sound-toggle");
8+
const tickSound = document.querySelector(".tick-sound");
9+
10+
let audioEnabled = false;
711

812
const days = [
913
"Sunday",
@@ -29,14 +33,45 @@ const months = [
2933
"Dec",
3034
];
3135

36+
const loadSavedTheme = () => {
37+
const savedTheme = localStorage.getItem("theme");
38+
const html = document.querySelector("html");
39+
40+
if (savedTheme === "dark") {
41+
html.classList.add("dark");
42+
toggle.innerHTML = "Light mode";
43+
} else {
44+
html.classList.remove("dark");
45+
toggle.innerHTML = "Dark mode";
46+
}
47+
};
48+
49+
soundToggle.addEventListener("click", () => {
50+
audioEnabled = !audioEnabled;
51+
const icon = soundToggle.querySelector("i");
52+
53+
if (audioEnabled) {
54+
icon.className = "fas fa-volume-up";
55+
soundToggle.title = "Disable sound";
56+
} else {
57+
icon.className = "fas fa-volume-mute";
58+
soundToggle.title = "Enable sound";
59+
tickSound.pause();
60+
tickSound.currentTime = 0;
61+
}
62+
});
63+
3264
toggle.addEventListener("click", (e) => {
3365
const html = document.querySelector("html");
3466
if (html.classList.contains("dark")) {
3567
html.classList.remove("dark");
3668
e.target.innerHTML = "Dark mode";
69+
// Save the User's Theme
70+
localStorage.setItem("theme", "light");
3771
} else {
3872
html.classList.add("dark");
3973
e.target.innerHTML = "Light mode";
74+
localStorage.setItem("theme", "dark");
4075
}
4176
});
4277

@@ -82,8 +117,16 @@ const setTime = () => {
82117
minutes < 10 ? `0${minutes}` : minutes
83118
} ${ampm}`;
84119
dateElement.innerHTML = `${days[day]}, ${months[month]} <span class="circle">${date}</span>`;
120+
121+
// Add a Ticking Sound
122+
if (audioEnabled) {
123+
tickSound.currentTime = 0;
124+
tickSound.play().catch((e) => console.log("Audio play failed:", e));
125+
}
85126
};
86127

128+
loadSavedTheme();
129+
87130
setTime();
88131

89132
setInterval(setTime, 1000);

019-theme clock/sounds/tick.mp3

314 KB
Binary file not shown.

019-theme clock/style.css

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,20 @@
44
box-sizing: border-box;
55
}
66

7+
/* Create Your Own Theme */
78
:root {
8-
--primary-color: #000;
9-
--secondary-color: #fff;
9+
--primary-color: #0f0f26;
10+
--secondary-color: #f2f0f0;
11+
--accent-color: #3498db;
1012
}
1113

1214
html {
1315
transition: all 0.5s ease-in;
1416
}
1517

1618
html.dark {
17-
--primary-color: #fff;
18-
--secondary-color: #333;
19+
--primary-color: #f2f0f0;
20+
--secondary-color: #0f0f26;
1921
}
2022

2123
html.dark {
@@ -33,16 +35,25 @@ body {
3335
margin: 0;
3436
}
3537

36-
.toggle {
38+
.toggle,
39+
.sound-toggle {
3740
background-color: var(--primary-color);
3841
color: var(--secondary-color);
3942
border: 0;
4043
border-radius: 4px;
4144
padding: 8px 12px;
4245
position: absolute;
46+
cursor: pointer;
47+
}
48+
49+
.toggle {
4350
top: 10px;
4451
right: 10px;
45-
cursor: pointer;
52+
}
53+
54+
.sound-toggle {
55+
bottom: 10px;
56+
left: 10px;
4657
}
4758

4859
.toggle:focus {
@@ -82,14 +93,15 @@ body {
8293
height: 100px;
8394
}
8495

96+
/* Change the Clock Hand Colors */
8597
.needle.second {
86-
background-color: #e74c3c;
98+
background-color: var(--accent-color);
8799
transform: translate(-50%, -100%) rotate(0deg);
88100
height: 100px;
89101
}
90102

91103
.center-point {
92-
background-color: #e74c3c;
104+
background-color: var(--accent-color);
93105
width: 10px;
94106
height: 10px;
95107
position: absolute;

0 commit comments

Comments
 (0)