'Uncaught TypeError: Cannot read properties of undefined (reading 'alt')

I could find an error as alt is undefined when I run the code in this line.

captionText.innerHTML =dots[slideIndex-1].alt;



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source