This is a count up timer, counting up in time from when the page is loaded, I was to make a function called resetcountupDate() which sets it back to zero by making the variable countupDate equal to the current date (using date() or something), and I want the button on the 4th to last line to do the function, my code below doesn't work in terms of resetting the timer.
<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" , charset="UTF-8">
<style>
@import url('https://fonts.googleapis.com/css2?family=Roboto+Slab:wght@100&display=swap');
p {
font-family: 'Roboto Slab', serif;
text-align: center;
font-size: 60px;
margin-top: 0px;
}
</style>
</head>
<body>
<p id="demo"></p>
<p></p>
<p></p>
<p></p>
<p></p>
<script>
// Set the date we're counting up from
var countupDate = new Date();
function resetcountupDate() {
var countupDate;
countupDate = Date();
}
// Update the count up every 1 second
var x = setInterval(function() {
// Get today's date and time
var now = new Date().getTime();
// Find the distance between now and the count up date
var distance = now - countupDate;
// Time calculations for days, hours, minutes and seconds
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
// Output the result in an element with id="demo"
document.getElementById("demo").innerHTML = days + "d " + hours + "h " +
minutes + "m " + seconds + "s ";
}, 1000);
</script>
<input type=button value="Show Time" onclick="resetcountupDate();">
</body>
</html>