slides.length -1 means count <9 so it means it only can rich to 8 because it is not count <=9 and it is count <9 . so <p> should never show number 10 from array but why it showing it ?
const btnNext = document.querySelector('.next'); const slides = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; let count = -1; btnNext.addEventListener('click', function () { if (count >= -1 && count < slides.length - 1) { count++; } else { count = 0; } document.querySelector('p').textContent = slides[count]; });
Обсуждают сегодня