How to link two pieces of code?

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

<div class="mySlides fade">
 <img src="" style="width:100%">

<div class="mySlides fade">
 <img src="" style="width:100%">

<div class="mySlides fade">
 <img src="" style="width:100%">

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


* {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;

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):
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
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() {
}, 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() {
}, 2000);

Find more questions by tags JavaScript