Show JS Alert after 5 seconds
<p>I am trying to show a JS alert after 5 seconds. Right now I have this code:</p>

<pre><code>&lt;script&gt;
function init() {
    var count=5;
    var counter=setInterval(timer,1000);
        function timer(){
            count=count-1;
            if(count==0){
                alert("This is an alert")
                window.location = "http://www.example.com";      
                return;
            } 
        }
    }
    window.onload = init;
&lt;/script&gt;
</code></pre>

<p>The problem is that it's not working right. There is some kind of little error I can't see in the code.</p>