Creating a slide show



write a JavaScript code to create a slide show.


<html>
  <head>
    <script>

          img_array = new Array ('vegetables1.jpg', 'vegetables2.jpg', 'vegetables3.jpg', 'vegetables4.jpg');
          img = 0; 

          function DisplayImg(num) 
          {
                img =  img + num; 
                if (img > img_array.length - 1) 
                {
                    img = 0;
                }
    
                if (img < 0) 
                {
                    img = img_array.length - 1;
                }
                document.Slide.src = img_array[img];
          }
          
    </script>
  </head>
<body>

        <img src="vegetables1.jpg" width="400" height="280" name="Slide" />
        <br><br>
    
        <input type="button" value="Previous" onclick="DisplayImg(-1)" />
        <input type="button" value="Next" onclick="DisplayImg(1)" />
        
  </body>
</html>

Output: