title: JavaScript - Uncaught TypeError: Cannot read properties of undefined (reading 'style')
body: <p>I got an Image-Slider in a website and in the Console, there is the following Error-Message:</p>
  <blockquote>
  <p>Uncaught TypeError: Cannot read properties of undefined (reading 'style')
  at showSlides (Script.js:64)
  at Script.js:40</p>
  </blockquote>
  <blockquote>
  <p>showSlides @ Script.js:64,
  (anonymous) @ Script.js:40</p>
  </blockquote>
  <p>The Error dosent affect the slider in any way, but i want to fix it.</p>
  <p><strong>JavaScript Code:</strong></p>
  <pre><code>var slideIndex = 1;
  showSlides(slideIndex);
  
  // Next / Previous controls
  function plusSlides(n) {
    showSlides(slideIndex += n);
  }
  
  // Thumbnail image controls
  function currentSlide(n) {
    showSlides(slideIndex = n);
  }
  
  function showSlides(n) {
    var i;
    var slides = document.getElementsByClassName(&quot;sliderImage&quot;);
    var dots = document.getElementsByClassName(&quot;imageSliderDot&quot;);
    if (n &gt; slides.length) {slideIndex = 1}
    if (n &lt; 1) {slideIndex = slides.length}
    for (i = 0; i &lt; slides.length; i++) {
        slides[i].style.display = &quot;none&quot;;
    }
    for (i = 0; i &lt; dots.length; i++) {
        dots[i].className = dots[i].className.replace(&quot; active&quot;, &quot;&quot;);
    }
    slides[slideIndex-1].style.display = &quot;block&quot;;
    dots[slideIndex-1].className += &quot; active&quot;;
  }
  </code></pre>