I have a game that I am trying to get going that displays a random card, but it draws duplicates. I don't want to duplicates to be used. I am using about 100 images-I just put the few in so you guys would understand.
How can I make it so it doesn't show any duplicates? Thank you in advance, I have checked elsewhere, and with numbers it seems easier. I am a little lost using images...
<script>
var cards = new Array();
cards.push("images/apple.jpg");
cards.push("images/pear.jpg");
cards.push("images/banana.jpg");
cards.push("images/grape.jpg");
cards.push("images/tree.jpg");
cards.push("images/dog.jpg");
cards.push("images/cat.jpg");
cards.push("images/house.jpg");
var lastPics = new Array();
var currentPic = cards[0];
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function pickimg2() {
var image = cards[getRandomInt(0, cards.length - 1)];
var innerHtml = ""
document.randimg.src = image;
document.getElementById("copy").src = image;
lastPics.splice(0,0,image);
if (lastPics.length > 5) {
lastPics.pop();
}
lastPics.forEach(function(item){
innerHtml = innerHtml + "<img name='copy' style='width:200px;height:200px;display:inline-block;padding:10px 10px 0px 10px;box-shadow: 0 12px 8px -8px black;' src="+item+" />"
});
document.getElementById("lastPicsDiv").innerHTML = innerHtml;
}
</script>
Aucun commentaire:
Enregistrer un commentaire