I have two banners which I added recently to my website and I'd like to change the banners every 5 seconds, unfortunately, it shows only the first one and freezes
<script>
var links = ["http://site","http://site"];
var images = ["/uploads/ad1.png","/uploads/ad2.png"];
var i = 0;
var renew = setInterval(function(){
if(links.length == i){
i = 0;
}
else {
document.getElementById("bannerImage").src = images[i];
document.getElementById("bannerLink").href = links[i];
i++;
}
},500);
</script>
<div class="container"><div class="text-center"><a id="bannerLink" href="http://site" onclick="void window.open(this.href); return false;"><img id="bannerImage" src="/uploads/ad1.png" width="320" height="120" alt="some text"></a></div></div>