I am trying to make it so that there are two buttons using Javascript, one to stop the image carousel using clearInterval which works well, however, I also want another button to restart the carousel however I can't figure out how to do so.
<img src="images/img1.jpg" id="images" width="200px"> <button type="button" id="stop">Stop the Carousel</button> <button type="button" id="start">Start the Carousel</button> <script> document.getElementById('stop').addEventListener('click', stopit); var start = 1; var timer = setInterval(carousel, 2000); function carousel(){ var image_data; start = start % 5; image_data = "images/img" + (start+1) + ".jpg"; document.getElementById('images').src=""+ image_data; start++; } function stopit(){ clearInterval(timer); } </script>