I'm trying to apply my code in one simple function
with parameters and make it reusable due to the DRY principle. As you can see I use pretty the same code in both of my addEventListener Function
.
Here is the code that I want to make reusable in my addEventListener function
:
rightBtn.addEventListener("click", () => {
activeSlide++;
if (activeSlide > slides.length - 1) {
activeSlide = 0;
}
});
leftBtn.addEventListener("click", () => {
activeSlide--;
if (activeSlide < 0) {
activeSlide = slides.length - 1;
}
});