Advertisement
Guest User

Cosas

a guest
Aug 28th, 2014
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function (document, window) {
  2.     'use strict';
  3.  
  4.     /**
  5.      * Creates a random image element
  6.      * @param {HTMLElement|Node} elem
  7.      * @param {String} location
  8.      * @param {Array} images
  9.      */
  10.     var randomImage = function (elem, location, images) {
  11.         if (!Array.isArray(images) || images.length === 0 || !elem || !location) {
  12.             throw "Invalid arguments";
  13.         }
  14.  
  15.         var img = document.createElement('img');
  16.         img.src = location + images[Math.floor(Math.random() * images.length)];
  17.         elem.appendChild(img);
  18.     };
  19.  
  20.     // Expose method
  21.     window.randomImage = randomImage;
  22. }(document, window));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement