Im working on a larger project but I'm trying out a simpler version of countdown timer with only seconds and not minutes. Code below description
So basically I have 60 seconds in html(id="initial"). I have button with a function called timer. In javascript i get the value in the h3 tag, by using parseint on the variable and of course innerHTML to get the text inside the tag itself.
Then I create a new variable called newTime and basically set it to newTime = initial--; Then I update the initial with innerHTMl, like initial.inneHTML = newTime. It doesnt work, however. Anyways heres the code:
setInterval(setUp, 1000);
function setUp(){
var initial = parseInt(document.getElementById("initial").innerHTML);
var newTime = initial--;
initial.innerHTML = newTime;
}
<button onclick="setUp()">Activate timer</button>
<h3 id="initial">60</h3>