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);

img.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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!