Here is what I worked out; I never actually used the hours or minutes values in the HTML to start with. I was only using the seconds, calculating all the labels with that. The totalSeconds variable should account for the hours and minutes.
So here is the code I ended up with…
if(document.getElementById("counter")){consthoursLabel=document.getElementById("hours");constminutesLabel=document.getElementById("minutes");constsecondsLabel=document.getElementById("seconds");// add all the time values together to give a proper total start pointlettotalSeconds=Number(secondsLabel.textContent)+Number(minutesLabel.textContent*60)+Number(hoursLabel.textContent*3600);setInterval(setTime,1000);functionsetTime(){++totalSeconds;// pull the number of hours out of the total for referenceconstnumHours=parseInt(totalSeconds/3600)//remove that number fromt he total because it messes up the /60 math if you have extra 3600's in thereconstsecondsLeft=parseInt(totalSeconds-3600*numHours)// tweak these for new variables availablesecondsLabel.innerHTML=padWithZero(secondsLeft%60);minutesLabel.innerHTML=padWithZero(parseInt(secondsLeft/60));hoursLabel.innerHTML=padWithZero(numHours);}functionpadWithZero(num){returnNumber(num).toString().padStart(2,"0");}}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Here is what I worked out; I never actually used the hours or minutes values in the HTML to start with. I was only using the seconds, calculating all the labels with that. The
totalSeconds
variable should account for the hours and minutes.So here is the code I ended up with…