1
Good afternoon, I have a question. I intend that when we click on a button a random image of an 80-card deck will appear. Then if we click again on that same button, another card appears next to the first one and so on. I’ve been searching and I can’t...
<img id="image" width="220" style="box-shadow: rgb(158, 120, 137) 0px 0px 20px 0px; border-radius: 0.5em" src="h"></img>
here is where, supposedly will appear the cards, and the JS I have is:
images = [{source: "https://i.ibb.co/xC9r03B/0.jpg"},
{source: "https://i.ibb.co/hD5gs5R/1.jpg"},
...
...]
var usedImages = [];
function random(){
var numberOfImages = images.length;
var num = getRandomInt(0, numberOfImages);
console.log(num);
if (usedImages.indexOf(num) === -1) {
document.getElementById("image").src = images[num].source;
document.getElementById("text").innerHTML = images[num].text;
usedImages.push(num);
}
else {
if (usedImages.length === numberOfImages) {
usedImages = [];
}
pickImage();
}
};
function getRandomInt(min, max) {
min = Math.ceil(0);
max = Math.floor(images.length - 1);
return Math.floor(Math.random() * (max - min)) + min;
}
Can someone give me a hand? thank you.
Thank you very much João, just say one thing, it’s working, but if I just want to appear 3 cards side by side, as I do??
– didi
You can use a display grid in the container there in css and put a grid-template-column: repeat(3, 1fr). I will edit the post and comment for you!
– João Azevedo
Thank you very much! I’m waiting John!
– didi
I already edited, see if this is what you wanted. If you have a doubt just call =D
– João Azevedo
Mega bro thanks, I e-mailed you to explain better! hug
– didi