javascript function that runs a timer of 24 hours
xxxxxxxxxx
function twentyFourHourTimer() {
const endTime = Date.now() + 24 * 60 * 60 * 1000; // Calculate the end time (24 hours from now)
const interval = setInterval(() => {
const remainingTime = endTime - Date.now(); // Calculate the remaining time
if (remainingTime < 0) { // If time is up
clearInterval(interval); // Stop the interval
console.log("Time's up!"); // Log a message
} else { // If time is still remaining
const hours = Math.floor(remainingTime / (60 * 60 * 1000)); // Calculate the remaining hours
const minutes = Math.floor((remainingTime % (60 * 60 * 1000)) / (60 * 1000)); // Calculate the remaining minutes
const seconds = Math.floor((remainingTime % (60 * 1000)) / 1000); // Calculate the remaining seconds
console.log(`Time remaining: ${hours} hours, ${minutes} minutes, ${seconds} seconds`); // Log the remaining time
}
}, 1000); // Update the timer every second (1000 milliseconds)
}
twentyFourHourTimer();