Question: HTML JavaScript var iconImg; var pictures = [ img1, img2, img3 ]; var index = 0; function pickImage(){ iconImg.setAttribute(src, pictures[index] + .png); iconImg.setAttribute(alt, descriptions[index]); index
HTML
JavaScript
var iconImg;
var pictures = [ "img1", "img2", "img3" ];
var index = 0;
function pickImage(){
iconImg.setAttribute("src", pictures[index] + ".png");
iconImg.setAttribute("alt", descriptions[index]);
index = (index + 1) % pictures.length;
}
function start(){
iconImg = document.getElementById("image");
int = setInterval(function() {pickImage()}, 1000);
}
The snippet above continuously changes the image at random as the image is clicked.
Update the start() function such that when the image is clicked again the action stops on the latest image.
Hint : add a flag to see if the images are changing, if not, continuously change images randomly ad set flag to yes and if yes, stop the action and set flag to no.
JQuery is not allowed
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
