Javascript image carousel
There are several problems with your code right now. 


Don't create global variables. nextIndex and prevIndex are both globals that are implicitly created when you first assign to them. 
Don't abuse not using braces on if statements. It is fine to skip them for a very simple statement (assuming it is allowed in your style guide) but nesting multiple ifs without braces is a recipe for disaster. 

// Much safer 
if (slider.getAttribute("src") == item) {
  if(index != images.length-1)
    nextIndex = index+1;
  else
   nextIndex = 0;
}

Don't use setAttribute / getAttribute if you are accessing a standard property on an element. slider.src is shorter and easier to read than slider.getAttribute('src'). 
Consider making your code more modular. What happens if you now want two sliders on the page? Ideally, it should just be another line of code to add the functionality (or maybe even no more lines of code!)
Consider preloading images. TimSparrow mentioned this in the comments - with your current code the next image won't be loaded until the user clicks on the next button. This can result in a bad experience on slow connections.




There are a few more things I could say, but I believe it would be more helpful to just provide an alternative implementation. 

This implementation has a couple advantages: 


You can just add another image-slider div wherever you want another set of images. 
By using an internal hidden div for storing the images, you automatically get preloaded images.




function createSlider(container) {
  const images = container.querySelectorAll('.images &gt; img');

  const displayImage = container.querySelector('[data-display]')

  // State
  let imageIndex;
  
  function setImage(index) {
    imageIndex = index;
    displayImage.src = images[index].src;
  }

  // Show the first image initially
  setImage(0);

  // Button listener
  container.addEventListener('click', event =&gt; {
    if (event.target.hasAttribute('data-prev')) {
      setImage(imageIndex === 0 ? images.length - 1 : imageIndex - 1)
    } else if (event.target.hasAttribute('data-next')) {
      setImage(imageIndex === images.length - 1 ? 0 : imageIndex + 1)
    }
  });
}

document.querySelectorAll('.image-slider').forEach(createSlider);
.image-slider .images {
  display: none;
}
&lt;div class="image-slider"&gt;
  &lt;div class="images"&gt;
    &lt;img src="https://placeimg.com/200/100/animals"&gt;
    &lt;img src="https://placeimg.com/200/100/arch"&gt;
    &lt;img src="https://placeimg.com/200/100/nature"&gt;
  &lt;/div&gt;
  &lt;button data-prev&gt;Prev&lt;/button&gt;
  &lt;img data-display width="200px" height="100px"&gt;
  &lt;button data-next&gt;Next&lt;/button&gt;
&lt;/div&gt;