So I'm relatively new to Javascript but I'm making a memory game in html using javascript. I'm using an api to fetch 18 images and I put them all in an array twice, so I can shuffle the list and assign the images to my 36 cards.
var images_list = [];
var response = fetch('https://dog.ceo/api/breeds/image/random')
.then(response => response.json())
.then(data => {
images_list.push(data.message);
images_list.push(data.message);
});
shuffle(images_list);
After this I get all the 36 memory-cards and assign them all one of the pictures.
var backViewList = document.getElementsByClassName("back-view");
for (var i=0; i < backViewList.length; i++) {
console.log(images_list);
var img = backViewList[i].querySelector("img");
img.src = images_list[i];
}
the console.log(images_list);
shows me an array with 36 url's to images, as you would expect. But when I console.log(images_list[0];
or any other index, this returns undefined. I can't seem to figure out why he does this. Can anyone explain this to me?