-1

When I put this code in HTML file, my slideshow works, but when I put it in an external js file, the slideshow doesn't work. why?

https://imgur.com/a/7qrxQd9 ............................................................

full code html: https://pastebin.com/YiZhpYzk javascript file: https://pastebin.com/11BNhL7G

var myIndex = 0;    
carousel();

function carousel() {
    var i;
    var x = document.getElementsByClassName("mySlides");
    for (i = 0; i < x.length; i++) {
        x[i].style.display = "none";  
    }
    myIndex++;
    if (myIndex > x.length) {myIndex = 1}    

    x[myIndex-1].style.display = "block";  
    setTimeout(carousel, 1300); 
}

1 Answers1

-1

Try placing the entry point of the link to your js document which includes the function in different places like just before the the tag and make sure the link to your css is correct.