Question: HTML Random JavaScript var img; var picturesArray = [ img1, img2, img3, img4 ]; var index = 0; function pickRandomImage(){ var index = Math.floor(Math.random() *
HTML
JavaScript
var img;
var picturesArray = [ "img1", "img2, "img3", "img4" ];
var index = 0;
function pickRandomImage(){
var index = Math.floor(Math.random() * picturesArray.length);
iconImg.setAttribute("src",picturesArray[index] + ".jpg");
}
function RandomImage(){ // your solution goes here
}
Given the HTML and Javascript snippets above, write the Javascript function RandomImage such that it replaces the placeholder image with a randomly generated image from "picturesArray" each time the button "Random" is clicked.
(No JQuery Allowed)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
