Code in Image:
The Code in Text Form:
<section>
<img class="mySlides" src="mosque.jpg" style="width:100%">
<img class="mySlides" src="img_band_ny.jpg" style="width:100%">
<img class="mySlides" src="img_band_chicago.jpg" style="width:100%">
</section>
<script>
// Automatic Slideshow - change image every 3 seconds
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, 3000);
}
</script>
Greetings everyone, currently I am learning to create a website and was planning to do a slideshow at the website. I found the tutorial at W3school (Link:https://www.w3schools.com/howto/howto_website.asp).But I have problem in understand the the code state above. To be specific the x.length. May I ask what does the x.length do in this example? Does it same with length function which are used in counting the number of character in the string? But in this example I only have image, so what does the length are for ?