An image gallery: A new random image

  1. Always advance
  2. An image gallery
  3. Extra credit

One of the nice things about using classes is that the shared information on the object makes it easier to add new functionality. Suppose we want to be able to display a random image, as we did earlier with a function? In the SlideShow class, it becomes a two-line function:

this.randomSlide = function() {

this.currentSlide = Math.floor(Math.random()*this.slides.length);

this.advance();

}

And then add this, for example, to the beginShow() function so that a random images shows on page load again:

//create a gallery and start the slide show

function beginShow() {

gallery = new SlideShow();

gallery.randomSlide();

window.setTimeout(advanceSlide, 30000);

}

By manipulating the data that already exists on the object, you can easily add new functionality.

  1. Always advance
  2. An image gallery
  3. Extra credit