let currentIndex = 0; function showSlide(index) { const slides = document.querySelectorAll('.carousel-item'); if (index >= slides.length) { currentIndex = 0; } else if (index < 0) { currentIndex = slides.length - 1; } else { currentIndex = index; } const offset = -currentIndex * 100; document.querySelector('.carousel-inner').style.transform = `translateX(${offset}%)`; } function nextSlide() { showSlide(currentIndex + 1); } function prevSlide() { showSlide(currentIndex - 1); } // Optional: Automatically move to the next slide every 3 seconds setInterval(nextSlide, 8000);