jquery - JavaScript count down, add hours & minutes -
so, have below (seconds countdown) in order. but! trying add hours & minutes apart of count down well. ideally keeping same structure, , using pure js. output be:
there x hours, x minutes, , x seconds remaining on sale!
var count=30; var counter=setinterval(timer, 1000); //1000 run every 1 second function timer() { count=count-1; if (count <= 0) { clearinterval(counter); return; } document.getelementbyid("timer").innerhtml=count + " secs"; // watch spelling }
if solution has rewrite jquery or library; that's fine. not preferable. cheers , salutations help.
something this:
var count = 30; var counter = setinterval(timer, 1000); //1000 run every 1 second function timer() { count = count - 1; if (count == -1) { clearinterval(counter); return; } var seconds = count % 60; var minutes = math.floor(count / 60); var hours = math.floor(minutes / 60); minutes %= 60; hours %= 60; document.getelementbyid("timer").innerhtml = hours + "hours " + minutes + "minutes and" + seconds + " seconds left on sale!"; // watch spelling }
Comments
Post a Comment