Create a seconds countdown in 6 lines of JavaScript

November 4th, 2017 | #javascript #html

TIL how to create a seconds countdown in just 6 lines of JavaScript.

var seconds = document.getElementById("countdown").textContent;
var countdown = setInterval(function() {
    seconds--;
    document.getElementById("countdown").textContent = seconds;
    if (seconds <= 0) clearInterval(countdown);
}, 1000);
Read more

© 2018 Tonny Garić | With from Nijmegen, The Netherlands