this is my code: I want to change the img src by clicking on the button and add one to the counter that change the next photo again But only the first photo is displayed ! and I have 8 img in this path : images/slides/writing${0-7};
slider = () =>{
let i=0;
let slides = document.getElementById('slides').getElementsByTagName('img')[0];
slides.src = `images/slides/writing${i}.jpg` ;
i++
}
<section id="slides">
<picture>
<img src="" alt="Slide img">
<input type="button" value="change" onclick="slider()">
</picture>
</section>
i = 0every timeslider()is called (and it's a new variable every time because you declare it locally withlet). Move this line outside of the function:let i=0;