Writing a simple seconds countdown timer with vanilla JavaScript

It’s the final countdown:


For this script, all you need to do is surround the number you want to start counting down with:

<div id="countdown">10</div>

Then use the following JavaScript:

<script type="text/javascript">
  var seconds;
  var temp;

  function countdown() {
    seconds = document.getElementById('countdown').innerHTML;
    seconds = parseInt(seconds, 10);

    if (seconds == 1) {
      temp = document.getElementById('countdown');
      temp.innerHTML = "all done, bye bye";

    temp = document.getElementById('countdown');
    temp.innerHTML = seconds;
    timeoutMyOswego = setTimeout(countdown, 1000);


7 thoughts on “Writing a simple seconds countdown timer with vanilla JavaScript”

What do you think?