I'm trying to create a simple timer in javascript that counts down from 5 to 0 on a push of a button. This is my function that I have for the onclick of the button. I'm getting stuck though since it is not counting down. Any hints to where my logic is wrong would be apprciated. Thanks.
function countdown(num) {
if (num >= 0) {
document.getElementById("counter").innerHTML=num;
timer=setTimeout("countdown()", 1000);
num--;
}
else
clearTimeout(timer);
}