I have a countdown timer function here below, which counts down from 30:00. What I need is the exact same function but it counts UP from 30:00. So one second in, it should read 30:01 and so on.
Would be grateful if someone could point me in the right direction!
……………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………….
var secondsRemaining;
var intervalHandle;
function resetPage(){
document.getElementById("inputArea").style.display = "block";
}
function tick(){
// grab the h1
var timeDisplay = document.getElementById("time");
// turn the seconds into mm:ss
var min = Math.floor(secondsRemaining / 60);
var sec = secondsRemaining - (min * 60);
//add a leading zero (as a string value) if seconds less than 10
if (sec < 10) {
sec = "0" + sec;
}
// concatenate with colon
var message = min.toString() + ":" + sec;
// now change the display
timeDisplay.innerHTML = message;
// stop is down to zero
if (secondsRemaining === 0){
clearInterval(intervalHandle);
resetPage();
}
//subtract from seconds remaining
secondsRemaining--;
}
function startCountdown(){
function resetPage(){
document.getElementById("inputArea").style.display = "block";
}
// get countents of the "minutes" text box
var minutes = document.getElementById("minutes").value;
// check if not a number
if (isNaN(minutes)){
alert("Please enter a number");
return; // stops function if true
}
// how many seconds
secondsRemaining = minutes * 60;
//every second, call the "tick" function
// have to make it into a variable so that you can stop the interval later!!!
intervalHandle = setInterval(tick, 1000);
// hide the form
document.getElementById("inputArea").style.display = "none";
}
window.onload = function(){
startCountdown();
//add to the DOM, to the div called "inputArea"
document.getElementById("inputArea").appendChild(inputMinutes);
document.getElementById("inputArea").appendChild(startButton)
document.getElementById("button").click();
}
1