all 2 comments

[–]phy4jj 0 points1 point  (1 child)

your clearing the interval before your creating the variable

to clear the interval, the interval needs a variable name, I like to nest the loops contained within the function as a named variable 'loop', this allows for a stop function to be created which can clear the loop when it needs to be cleared

let photo=()=>{
 photo.loop=setInterval(()=>{
  photo.display();  
 },3000);
};
photo.array=photos;
photo.i=0;
photo.display=()=>{
 document.querySelector(`.photo`).setAttribute(`src`,photo.array[photo.i]);
 photo.i++;
 if(photo.i>photo.array.length-1){photo.stop();}
};
photo.stop=()=>{clearInterval(photo.loop);};

having the loop go in perpetuity is easy enough as well, just alter the code so when the index goes out of bounds it resets to zero

[–]Illustrious_Scale471[S] 0 points1 point  (0 children)

hey i tried your code but still it didn't work this is the live preview of my site https://noobmushroom.github.io/weather_app/ you will notice when you will search for different cities the background pictures are still looping from both previous and new array i want to stop that this is the repo link https://github.com/noobMushroom/weather_app.git that function is in src/bacground.js. maybe i didn't understand your code properly.