mercredi 1 mars 2017

practice for making a array of random image sizes javascript

Hello I am trying to make a Array that sets random image sizes for practice in one of my classes. The image is also random which has got me stuck on how to do it.

var size = [pictures.height = 100px,pictures.height = 200px,pictures.height = 300px]
var iconImg; 
var pictures = [ "CPE", "EPT", "GPP"];
var descriptions = [ "Common Programming Error", 
   "Error-Prevention Tip", "Good Programming Practice"];

// pick a random image and corresponding description then modify
// the img element in the document's body 
function pickImage()
{
   var index = Math.floor( Math.random() * 3 );
   iconImg.setAttribute( "src", pictures[ index ] + ".png" );
   iconImg.setAttribute( "alt", descriptions[ index ] );
   iconImg.setAttribute( "src", size[ index ] + ".png" );
} // end function pickImage

// registers iconImg's click event handler
function start()
{
   iconImg = document.getElementById( "image" );
   iconImg.addEventListener( "click", pickImage, false );
} // end function start

window.addEventListener( "load", start, false );

Thanks for the help on this.




Aucun commentaire:

Enregistrer un commentaire