// Declare minPerSlide with a specific value let minPerSlide = 0; // Function to update minPerSlide based on screen width function updateMinPerSlide() { const screenWidth = window.innerWidth; if (screenWidth === 768) { minPerSlide = 6; } else if (screenWidth === 400) { minPerSlide = 4; } else { minPerSlide = 12; // Default value for other screen widths } } // Call updateMinPerSlide to initialize minPerSlide updateMinPerSlide(); // Iterate over carousel items let items = document.querySelectorAll('.carousel .carousel-item'); items.forEach((el) => { let next = el.nextElementSibling; // Use let instead of var for the loop counter for (let i = 1; i < minPerSlide; i++) { if (!next) { // Wrap the carousel by using the first child next = items[0]; } let cloneChild = next.cloneNode(true); el.appendChild(cloneChild.children[0]); next = next.nextElementSibling; } });