How to link two pieces of code?

There is a slider, with scrolling by clicking the arrows:
HTML:
<div class="slideshow-container">

<div class="mySlides fade">
 <img src="http://hq-wallpapers.ru/wallpapers/7/hq-wallpapers_ru_nature_33645_1920x1080.jpg" style="width:100%">
</div>

<div class="mySlides fade">
 <img src="http://luxfon.com/pic/201210/1920x1080/luxfon.com-16903.jpg" style="width:100%">
</div>

<div class="mySlides fade">
 <img src="http://wallpapers-image.ru/1920x1080/world/wallpapers/world-wallpapers-1920x1080-0002.jpg" style="width:100%">
</div>

<a class="prev" onclick="plusSlides(-1)">&#10094;</a>
<a class="next" onclick="plusSlides(1)">&#10095;</a>

</div>


CSS:
* {box-sizing: border-box}
body {font-family: Verdana, sans-serif; margin:0}
.mySlides {display: none}
img {vertical-align: middle;}

.slideshow-container {
 max-width: 1000px;
 position: relative;
 margin: auto;
}
.prev .next {
 cursor: pointer;
 position: absolute;
 top: 50%;
 width: auto;
 padding: 16px;
 margin-top: -22px;
 color: white;
 font-weight: bold;
 font-size: 18px;
 transition: 0.6 s ease;
 border-radius: 0 3px 3px 0;
 user-select: none;
}
.next {
 right: 0;
 border-radius: 3px 0 0 3px;
}
.prev:hover, .next:hover {
 background-color: rgba(0,0,0,0.8);
}


JS: (part 1)
var slideIndex = 1;
showSlides(slideIndex);

plusSlides function(n) {
 showSlides(slideIndex += n);
}


showSlides function(n) {
 var i;
 var slides = document.getElementsByClassName("mySlides");
 if (n > slides.length) {slideIndex = 1} 
 if (n < 1) {slideIndex = slides.length}
 for (i = 0; i < slides.length; i++) {
 slides[i].style.display = "none"; 
}
 slides[slideIndex-1].style.display = "block"; 
}


Want to do auto-scrolling slider due to the setTimeout.
Did its function (part 2):
autoSlider();
var timer;

function autoSlider(){
 timer=setTimeout(plusSlides, 2000); 
}

How this feature(part 2) to associate with the slider click-through(part 1) working code.
I just don't really understand how to apply one function to another.
March 23rd 20 at 19:33
1 answer
March 23rd 20 at 19:35
Solution
Here is a call to a function that scrolls the slider forward
<a class="next" onclick="plusSlides(1)">&#10095;</a>

You need to pass it to setTimeout
timer=setTimeout(function() {
plusSlides(1);
}, 2000);


In General, the setTimeout will fire once, if you wanted to scroll the slider was going constantly, you need to use setInterval
timer=setInterval(function() {
plusSlides(1);
}, 2000);

Find more questions by tags JavaScript