I am trying to build a website with a background that switches images every five seconds. I use javascript to achieve this. After some fiddling around i stumbled upon what seems to be a scope issue, as it keeps telling me that the var imageCount is undefined. i am a bit of a newbie regarding javascript and stackoverflow and i appreciate any help i could get.
html
<body>
<div id="overlay">
</div>
<script>
window.setInterval(execute, 5000);
var imageCount;
function execute() {
console.log("bla");
if(imageCount == 0){
document.body.style.backgroundImage = "url('huis1.jpg')";
console.log("huis1");
}
else if(imageCount == 1){
document.body.style.backgroundImage = "url('huis2.jpg')";
console.log("huis2");
}
else if(imageCount == 2){
document.body.style.backgroundImage = "url('huis3.jpg')";
console.log("huis3");
imageCount = 0;
}
console.log(imageCount);
}
</script>
</body>
i would like to also post the CSS to this file but i wouldn't know how to do it if my life depended on it.
imageCountto a value, so it'sundefined.