Q:

How to navigate through pictures in Javascript

I have an image slider which  changes pictures on the click of a next button and a previous button. So if the user clicks next the next picture in the sequence pops up and if the user clicks previous the previous one pops up. The next function works just fine but I cant seem to get the previous function to work.
<script type="text/javascript">

var image1 = new Image();
var image2 = new Image();
var image3 = new Image();
var image4 = new Image();
var image5 = new Image();
var image6 = new Image();
var image7 = new Image();
var image8 = new Image();
var image9 = new Image();
var image10 = new Image();
var image11 = new Image();

image1.src="jokes.png";
image2.src="facts.png";
image3.src="riddles.png";
image4.src="html.png";
image5.src="xml.png";

</script>

<img alt="previous" id="prev" src="prev_ctrl.png" width=60 height=60 onClick="slideprev()">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="jokes.png" name="slide" width="200" height="200">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img id="next" src="next_ctrl.png" alt="next" width=60 height=60 onClick="slidenext()">
<script type="text/javascript">
var step = 1;

function slidenext() {
  document.images.slide.src = eval("image" + step + ".src");
  if (step < 5){ 
     step++;
   }else{ 
    step = 1;
    }
}

function slideprev() {
  document.images.slide.src = eval("image" + step + ".src");
  if (step >= 5){ 
     step--;
   }else{ 
    step = 5;
    }
}

</script>

A:

function slideprev() {
  document.images.slide.src = "image"+step+".png";
      if (step <= 5 && step > 1){ 
         step--;
        }else{ 
             step = 5;
        }
    }

Just replace the slideprev function with the above, then that will work well.

