I'm having trouble getting the day to increment by 1, I think my math may be incorrect.
Here is what I have and where the issue lies:
- The counter works perfectly (100%)
- I've placed the number into an "id" tag as shown below.
- I just can't seem to figure out the correct math needed for 24 hours for some reason.
let daysLabel = document.getElementById("days");
let minutesLabel = document.getElementById("minutes");
let hoursLabel = document.getElementById("hours");
let totalSeconds = 0;
let dayUpdate = 0;
setInterval(setTime, 10);
function setTime() {
++totalSeconds;
if (totalSeconds / 60 == 24) {
++dayUpdate;
totalSeconds = 0;
}
minutesLabel.innerHTML = pad(parseInt(totalSeconds % 60));
hoursLabel.innerHTML = pad(parseInt(totalSeconds / 60));
// I believe there's an issue with my math which is why the time isn't updating.
daysLabel.innerHTML = pad(parseInt(totalSeconds / 60 == 24));
}
function pad(val) {
let valString = val + "";
if (valString.length < 2) {
return "0" + valString
}
return valString
}
<label id="days">Day: 1</label> <label id="hours">00</label>:<label id="minutes">00</label><br />
I tried copying the counter info in an attempt to increase the days count but failed. I cannot get the day to increment by +1 every new day based on the timer.
Day 1: 22:59 - time changes to 00:00 again and the day should increase by 1 Day 2: 00:01
My suggestions and thoughts on the issue are as follows:
The math formula might be incorrect. I think the pad() function needs to be removed. When the timer resets at 00:59 back to 0, I added code to increment the day by 1 (++days) but still no result. I'm wondering if anyone could offer a more efficient solution.
My game will run like this: Day: 1 00:00 - the counter counts 1 second every 15 seconds, allowing for more days in each round and more days in one actual day, giving users better chances as it's a round-based game with prizes.