-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
29 lines (25 loc) · 793 Bytes
/
script.js
File metadata and controls
29 lines (25 loc) · 793 Bytes
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
function handleOnClickEvent() {
let output = document.querySelector(".output");
output.style.display = "block";
let hours = document.getElementById('hours');
// When the zzz button is clicked, we want to record the current time;
let now = Date.now();
// Allow 14 minutes to fall asleep;
let minute = 60 * 1000; // milliseconds
now += 14 * minute;
// Create six cycles of 90 minutes each;
let hoursString = "";
for (let c = 1; c <= 6; c++) {
now += 90 * minute; // a sleep cycle passed!
let cycle = new Date(now);
hoursString += cycle.toLocaleTimeString([], {
hour: "2-digit",
minute: "2-digit",
});
if (c < 6) {
hoursString += ", ";
}
}
// Display the cycles as suggested wake-up times.
hours.innerText = hoursString;
}