Share Blog

Wednesday, July 04, 2018

Creating a Countdown Timer in Java Script


<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
p {
text-align: center;
font-size: 60px;
margin-top:0px;
}
</style>
</head>
<body>

<p id="demo"></p>

<script>
// Set the date we're counting down to
var seconds = 25;
interval = setInterval(function () {
seconds = seconds - 1;
// Output the result in an element with id="demo"
document.getElementById("demo").innerHTML = seconds;
// If the count down is over, write some text
if (seconds < 0) {
clearInterval(interval);
document.getElementById("demo").innerHTML = "EXPIRED";
}
}, 1000);
</script>

</body>
</html>

No comments:

Post a Comment