var element = document.querySelector("targetElement");
var isPaused = false;
var time = 0;
// setInterval here = update this function every 1 second
var t = setInterval(function() {
// if the time is not paused (isPaused is false)
// increment current Time by 1
if(!isPaused) {
time++;
element.innerText = "Seconds: " + time;
}
}, 1000); // 1000 = 1s
// play() starts the timer
function play(){
isPaused = false;
}
// when pause() function is called
// pause the timer and save the current time value to targeted Element or Variable
// in this case var = time
function pause(){
isPaused = true;
}