My goal is to cycle through images every 2 seconds in a specific order. I have implemented two functions, cycle and random. However, the cycle function seems to rotate too quickly and gets stuck without repeating itself in the correct order. On the other hand, the random function works perfectly fine, displaying a random image every 2 seconds.
<script>
var asgnimage = ["pic2.jpg","pic3.jpg", "pic1.jpg", "pic4.jpg"];
function cycle(){
for (i=0; i<asgnimage.length; i++){
document.cb.src = asgnimage[i];
window.setTimeout("", 2000);
}
window.setTimeout ("cycle()",2000);
}
function rndm(){
var randomIndex = Math.floor(Math.random(randomIndex) * 4)
document.rm.src = asgnimage[randomIndex];
setTimeout ("rndm()",2000);
}
</script>