I've been working on a project to create a basic slideshow with 3 rotating images that should restart as soon as the last one is displayed, with a 5000ms interval between each image.
<div id="slideshow"> </div>
<script type="text/javascript">
var imageArray = ['Image1','Image2','Image3'];
var currentIndex = 0;
nextPic = function(currentIndex,slideshow) {
var theHTML = '<img src="http://www.domain.com/Pics/Test-' + imageArray[currentIndex] + '.jpg">';
document.getElementById("slideshow").innerHTML = theHTML;
if (currentIndex < imageArray.length) {
currentIndex = currentIndex + 1;
}
else {
currentIndex = 0;
}
setTimeout("nextPic(" + currentIndex + ")", 5000);
}
nextPic(currentIndex, "slideshow");
</script>
Despite trying various versions of Javascript code, I keep encountering the same issue: after displaying the last image (Test-Image3.jpg), an attempt is made to display an undefined image ("Test-undefined.jpg") before resetting back to the first image. Everything works perfectly except for this hiccup, and it's quite frustrating.