Edrol97
Bronze Coder
Hi all, wondering about my code. Am wanting to build a slider gallery that loops and not really sure where to go from here. I've got the slider part but can't seem to find a way to loop it. I've seen various posts talking about const variables, and have copied code examples in and can't seem to figure out where I'm going wrong. The code I've copied is as followed:
JavaScript:
var image_count = 0;
function rollover (image_id, millisecs) {
var image = document.getElementById(image_id);
image.src = images[image_count];
image_count++;
if (image_count >= images.length) {
image_count = 0;
}
setTimeout("rollover('" + image_id + "'," + millisecs + ");",millisecs);
}
HTML:
<img src="image1.png" id="img1" >
And for the loop to be started:
HTML:
<script language="javascript">
rollover("img1",2000);
</script>
I've got a tutor in coding who has advised against using var and instead says to use let as he says var is outdated, but can't figure out how to do it anyway! Does anyone have any ideas for what I'm sure is a ridiculously simple problem?
Last edited by a moderator: