I have a website that displays from an array's index a shuffled ordering of images, one by one. I'm looking for a way to check the images all at once with a simple function, using onerror
most likely, to make sure the images still exist at their locations, and to alert me if they don't, but I'm not sure how to do it. I've tried fiddling around with forEach()
. I'm not sure what I'm doing wrong or right.
var backInfo = [
{ image: "https://dfep0xlbws1ys.cloudfront.net/thumbs71/df/71dfd3bb82eb215b00dd0bf1eb1be93d.jpg?response-cache-control=max-age=2628000",
artist: "http://loish.net/dawn/",
caption: "Breathe by Lois Van Baarle aka Loish" },
{ image: "http://66.media.tumblr.com/0d5f88148461e33581ca4120d02d38d4/tumblr_nn8q8yPofl1s8p1hwo1_1280.jpg",
artist: "http://cobaltplasma.tumblr.com/post/117141857207/finally-finished-the-companion-piece-to-another",
caption: "The Storm King by Denjin108" }, . . .
It goes on like that for quite some time. This next part is a shuffle that randomizes the images uniquely, which I didn't write.
function shuffle(array) {
var m = array.length, t, i;
while (m) {
i = Math.floor(Math.random() * m--);
t = array[m];
array[m] = array[i];
array[i] = t;
}
return array;
}
And then this part gets the keys so, one by one, when an image is clicked, it performs the pop()
function on variable mix
. It took me a while to learn that Object.keys()
was what I was looking for to do that.
var mix = shuffle(Object.keys(backInfo));
This is my JavaScript in total: http://www.dreamquest.io/javascript.js
And the live webpage: http://www.dreamquest.io/