1var colors=["red","blue","green"];
2for (let i = 0; i < colors.length; i++) {
3 console.log(colors[i]);
4}
1<body>
2
3<h2>Automatic Slideshow</h2>
4<p>Change image every 5 seconds:</p>
5
6
7<div class="slideshow-container">
8 <div class="mySlides fade">
9 <img src="img_nature_wide.jpg" style="width:100%">
10 </div>
11
12 <div class="mySlides fade">
13 <img src="img_snow_wide.jpg" style="width:100%">
14 </div>
15
16 <div class="mySlides fade">
17 <img src="img_mountains_wide.jpg" style="width:100%">
18 </div>
19</div>
20
21<br>
22
23
24
25<div class="row">
26 <div class="column">
27 <img id="myBtn" class="demo cursor stop_loop" src="img_woods.jpg" style="width:100%" onclick="currentSlide(0); breakLoop();">
28 </div>
29
30 <div class="column">
31 <img id="myBtn" class="demo cursor stop_loop" src="img_5terre.jpg" style="width:100%" onclick="currentSlide(1)">
32 </div>
33
34 <div class="column">
35 <img id="myBtn" class="demo cursor stop_loop" src="img_mountains.jpg" style="width:100%" onclick="currentSlide(2)">
36 </div>
37</div>
38
39
40
41
42
43<script>
44var slideIndex = 0; //indica che parto dall'immagine n.1
45showSlides();
46
47
48// script per lo slide delle immagini al click
49function plusSlides(n) {
50 showSlides(slideIndex += n);
51}
52
53function currentSlide(n) {
54 showSlides(slideIndex = n);
55}
56
57
58// funzione per mostrare le slides
59function showSlides() {
60 var i;
61 var slides = document.getElementsByClassName("mySlides");
62 var dots = document.getElementsByClassName("demo");
63 var exitLoop = 0; //interrompere il loop al click delle immagini
64
65 for (i = 0; i < slides.length; i++) {
66 slides[i].style.display = "none";
67 }
68 slideIndex++;
69
70 if (slideIndex > slides.length) {slideIndex = 1}
71 for (i = 0; i < dots.length; i++) {
72 dots[i].className = dots[i].className.replace(" active", "");
73 }
74
75 slides[slideIndex-1].style.display = "block";
76 dots[slideIndex-1].className += " active";
77
78
79
80 enter code here
81
82 if(exitLoop == 0) {
83 setTimeout(showSlides, 5000); // Change image every 5 seconds
84 }
85
86}
87</script>
88
89</body>
90</html>
1for (var i = 0; i < cats.length; i++) {
2 if (i === cats.length - 1) {
3 info += 'and ' + cats[i] + '.';
4 } else {
5 info += cats[i] + ', ';
6 }
7}
1//this is javascript
2var speed = 100;
3setInterval(function() {
4//DO SOMETHING THAT REPEATS
5},speed);
6