I've been working on a timer for a few weeks now. When I try to subtract minutes from 0, it goes into negatives without touching the hours. I've tried a few methods, read the documentation, and watched several YouTube videos, but none of them help me. Here's the code I used:
seconds--;
if (seconds === 0) {
seconds = 59;
minutes--;
if (minutes < 10) {
minutesText.innerText = '0' + minutes.toString()
} else {
minutesText.innerText = minutes;
}
if (minutes === 0) {
minutes = 59;
hours--;
if (hours < 10) {
hoursText.innerText = '0' + hours.toString()
} else {
hoursText.innerText = hours;
}
if (hours === 0) {
window.clearInterval(interval);
}
}
}
if (seconds < 10) {
secondsText.innerText = '0' + seconds.toString();
} else {
secondsText.innerText = seconds;
}
It never touches the hours--
and doesn't make minutes be equal to 59.
(Sorry if it's an easy fix, I'm just getting started on JS)
minutes--
do whenminutes
is0
? Willminutes === 0
catch that condition?