Iterating through an array of images

Hello everyone. I am trying to create a simple slideshow website. I managed to get the photo to change on the buttons click, however it will only change to the 2nd image. I know there is something wrong with my change function, but I am not skilled enough to see the solution.
I hope this won’t take too much of your time. Thank you.


const imageArray = ["https://www.worldatlas.com/r/w728-h425-c728x425/upload/1f/e7/fd/1280px-van-gogh-starry-night-google-art-project.jpg", "https://image.jimcdn.com/app/cms/image/transf/none/path/sa6549607c78f5c11/image/i6b743a5bd2529b6a/version/1500387064/unmissable-paintings-in-europe-la-clairvoyance-by-magritte.jpg", "https://1.bp.blogspot.com/-TXjauW9fiYc/Tqa1DtNwOwI/AAAAAAAACqs/LsacjFBdijU/s1600/famous_paintings_beautifularts_drawings_art_painting_waterhouse.jpg", "https://1.bp.blogspot.com/-TXjauW9fiYc/Tqa1DtNwOwI/AAAAAAAACqs/LsacjFBdijU/s1600/famous_paintings_beautifularts_drawings_art_painting_waterhouse.jpg", "https://wallpapercave.com/wp/yyZp2gA.jpg", "https://wallpapercave.com/wp/9myB9I9.jpg" ]

const DisplayImage = document.getElementById('painting1')
const imageIndex = 0;

function changeImage() {
  DisplayImage.setAttribute("src", imageArray[imageIndex]);
  imageIndex++ 
}

Link to full project if needed

imageIndex is declare as const , it is immutable The value of a constant can’t be changed through reassignment, and it can’t be redeclared (mdn site)
errors message in chrome dev toolserrors

replace const by let

1 Like

Solved, thank you.
deep down I knew that, however I forgot here.