I am in possession of a countdown timer that starts at zero and counts up to 100. The timer displays the count in a p tag with the ID of countdowntimer.
I am attempting to show the current time when I click a button while the timer is running.
Additionally, I would like to reset the timer after clicking the button.
Do you have any suggestions on how I can accomplish this task?
var timeleft = 1;
var downloadTimer = setInterval(function(){
timeleft++;
document.getElementById("countdowntimer").textContent = timeleft;
if(timeleft >= 100)
clearInterval(downloadTimer);
},1000);
function timenow()
{
var timenow=document.getElementById("timetaken").textContent = timeleft;
}
<p> Time <span id="countdowntimer">0 </span></p>
<p> Time Taken <span id="timetaken">0 </span></p>
<button onclick="timenow">Click to view time taken</button>