I'm still learning about Javacripts. This is one of my first assignment at home. However, I can't seem to get the codes to work even I tried follow steps by steps with the instructions. I need to create a slideshow where when I click on the button, there will be a new image until it cycled back to the first one. I checked everything but I still can't figure out what I did wrong. If you can explain and help, I'm very appreciated.
<body onload="startup();">
<center>
<img id="banner" src="images/bangkok_thailand.jpg">
<br>
<button onclick="cycle();">Click Here to Change Image</button>
<script>
var imgArray = new Array();
var index = 0;
function cycle() {
document.getElementById("banner").src = imgArray[index].src;
index = index + 1;
if (index > 5 ) {
index = 0;
}
return;
}
function startup()
{
imgArray[0] = new Image;
imgArray[1] = new Image;
imgArray[2] = new Image;
imgArray[3] = new Image;
imgArray[4] = new Image;
imgArray[5] = new Image;
imgArray[0]. src="images/bangkok_thailand.jpg";
imgArray[1]. src="images/paris_france.jpg";
imgArray[2]. src="images/seoul_southkorea.jpg";
imgArray[3]. src="images/tokyo_japan.jpg";
imgArray[4]. src="images/istanbul_turkey.jpg";
imgArray[5]. src="images/amsterdam_netherlands";
}
//cycle();
return;
</script>
</center>