Darrius Rankin Darrius Rankin - 14 days ago 4
HTML Question

Images won't show in slide show

The first image will appear but then the rest won't. I don't think the script can locate them. How do I direct it to my images?

// JavaScript Document

var myImgage=document.getElementById("slideshow");


var imageArray=["healing.jpg","holiday.jpg","nye.jpg","basketball.jpg"]

var imageIndex=0;

function changeImage () {
slideshow.setAttribute("src", imageArray [imageIndex]);
imageIndex++;
if (imageIndex>=imageArray.length) {
imageIndex=0;
}
}

var intervalHandle = setInterval(changeImage,2000);
slideshow.onclick=function () {
clearInterval(intervalHandle);
}

// Html

<img id="slideshow" src="image/healing.jpg" width="80%" height="40%"/>
<script src="java/slideshow.js"></script>

Answer

Try changing your imageArray to the following

var imageArray=["image/healing.jpg","image/holiday.jpg","image/nye.jpg","image/basketball.jpg"]