Closed simonjvardy closed 3 years ago
replaced alarmTime()
function code:
function alarmTime() {
let now = new Date();
/*
Return the time portion of a Date object as a string
in the format "hh:mm:ss"
*/
currentTime = now.toLocaleTimeString();
if (currentTime === alarmElement) {
alarmDisplay.play();
// Assign css class to bell icon to make the image shake
bellIconDiv.classList.add("bell-icon-shake");
}
setTimeout(alarmTime, 1000);
}
as the now.toLocaleTimeString()
is returned in different time formats depending on the developer
to this function code:
function alarmTime() {
/*
Return the time portion of a Date object as a string
in the format "hh:mm:ss"
*/
let currentDate = new Date();
let hour = currentDate.getHours();
let minute = currentDate.getMinutes();
let seconds = currentDate.getSeconds();
let currentTime = String(hour) + ":" + String(minute) + ":" + String(seconds);
if (currentTime === alarmElement) {
alarmDisplay.play();
// Assign css class to bell icon to make the image shake
bellIconDiv.classList.add("bell-icon-shake");
}
setTimeout(alarmTime, 1000);
}
Replace .toLocaleTimeString() with string concatenation from the Date() object hours, minutes and seconds values. This created a more stable cross-browser support - tested on Chrome, Firefox and Edge.