-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.js
More file actions
65 lines (55 loc) · 2.23 KB
/
Copy pathfunction.js
File metadata and controls
65 lines (55 loc) · 2.23 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
// Clock Functionality
function updateClocks() {
const localTime = new Date().toLocaleTimeString();
const nyTime = new Date().toLocaleTimeString("en-US", { timeZone: "America/New_York" });
const londonTime = new Date().toLocaleTimeString("en-US", { timeZone: "Europe/London" });
const tokyoTime = new Date().toLocaleTimeString("en-US", { timeZone: "Asia/Tokyo" });
document.getElementById("local-time").innerText = `Local Time: ${localTime}`;
document.getElementById("new-york-time").innerText = `New York: ${nyTime}`;
document.getElementById("london-time").innerText = `London: ${londonTime}`;
document.getElementById("tokyo-time").innerText = `Tokyo: ${tokyoTime}`;
}
setInterval(updateClocks, 1000);
// Timer Functionality
let timerInterval;
function startTimer() {
const minutes = parseInt(document.getElementById("timer-minutes").value) || 0;
const seconds = parseInt(document.getElementById("timer-seconds").value) || 0;
let totalSeconds = minutes * 60 + seconds;
if (timerInterval) clearInterval(timerInterval);
timerInterval = setInterval(() => {
const min = Math.floor(totalSeconds / 60);
const sec = totalSeconds % 60;
document.getElementById("timer-display").innerText = `${min.toString().padStart(2, "0")}:${sec.toString().padStart(2, "0")}`;
if (totalSeconds === 0) {
clearInterval(timerInterval);
alert("Timer Finished!");
}
totalSeconds--;
}, 1000);
}
function resetTimer() {
clearInterval(timerInterval);
document.getElementById("timer-display").innerText = "00:00";
}
// Alarm Functionality
let alarmTime = null;
let alarmInterval;
function setAlarm() {
alarmTime = document.getElementById("alarm-time").value;
const alarmSound = document.getElementById("alarm-sound");
if (alarmTime) {
document.getElementById("alarm-status").innerText = `Alarm Set for ${alarmTime}`;
if (alarmInterval) clearInterval(alarmInterval);
alarmInterval = setInterval(() => {
const currentTime = new Date().toTimeString().slice(0, 5);
if (currentTime === alarmTime) {
clearInterval(alarmInterval);
alarmSound.play();
alert("Alarm Ringing!");
}
}, 1000);
} else {
document.getElementById("alarm-status").innerText = "No Alarm Set";
}
}