My goal is to display a deck of cards on a webpage. There will be one button on the page per suit of cards, so four buttons for Hearts, Diamonds, Clubs, Spades, respectively. When the button to display all the hearts cards is clicked, I want to display each heart card one at a time for 3 seconds each in the div id "displayArea". The cards cannot be shown more than once, so I'm guessing they need to be placed in different array once they are displayed. Once all 13 cards have been displayed, I want the screen left blank. My images are stored, relative to my index.html file in "img/Hearts/cards/Ace.jpg". Here is my code so far:
$(document).ready(function(){
//cards already displayed
var displayedCards = new Array();
//card object
function card(name,suit) {
this.name = name;
this.suit = suit;
}
var deck = [
new card('Ace', 'Hearts'),
new card('Two', 'Hearts'),
new card('Three', 'Hearts'),
new card('Four', 'Hearts'),
new card('Five', 'Hearts'),
new card('Six', 'Hearts'),
new card('Seven', 'Hearts'),
new card('Eight', 'Hearts'),
new card('Nine', 'Hearts'),
new card('Ten', 'Hearts'),
new card('Jack', 'Hearts'),
new card('Queen', 'Hearts'),
new card('King', 'Hearts'),
new card('Ace', 'Diamonds'),
new card('Two', 'Diamonds'),
new card('Three', 'Diamonds'),
new card('Four', 'Diamonds'),
new card('Five', 'Diamonds'),
new card('Six', 'Diamonds'),
new card('Seven', 'Diamonds'),
new card('Eight', 'Diamonds'),
new card('Nine', 'Diamonds'),
new card('Ten', 'Diamonds'),
new card('Jack', 'Diamonds'),
new card('Queen', 'Diamonds'),
new card('King', 'Diamonds'),
new card('Ace', 'Clubs'),
new card('Two', 'Clubs'),
new card('Three', 'Clubs'),
new card('Four', 'Clubs'),
new card('Five', 'Clubs'),
new card('Six', 'Clubs'),
new card('Seven', 'Clubs'),
new card('Eight', 'Clubs'),
new card('Nine', 'Clubs'),
new card('Ten', 'Clubs'),
new card('Jack', 'Clubs'),
new card('Queen', 'Clubs'),
new card('King', 'Clubs'),
new card('Ace', 'Spades'),
new card('Two', 'Spades'),
new card('Three', 'Spades'),
new card('Four', 'Spades'),
new card('Five', 'Spades'),
new card('Six', 'Spades'),
new card('Seven', 'Spades'),
new card('Eight', 'Spades'),
new card('Nine', 'Spades'),
new card('Ten', 'Spades'),
new card('Jack', 'Spades'),
new card('Queen', 'Spades'),
new card('King', 'Spades')
];
function getRandom(num){
var my_num = Math.floor(Math.random()*num);
return my_num;
}
function displayHeartCards(){
do{
var index = getRandom(52);
var c = deck[index];
if(!$.inArray(index, displayedCards) > -1 && deck[index].suit == "Hearts"){
$("<img>").attr('src','images/cards/' + c.suit + '/' + c.name + '.jpg')
.appendTo("#displayArea")
.fadeOut('slow')
.fadeIn('slow');
displayedCards.push(c);
}
}
while {
}
}
$("#btnHearts").click(function(){
displayHeartCards();
});
$("#btnDiamonds").click(function(){
display();
});
$("#btnClubs").click(function(){
display();
});
$("#btnSpades").click(function(){
display();
});
});
And my HTML:
<div id="main">
<h1>Press a button to display each card in the suit</h1>
<ul>
<li>
<button id="btnHearts">Show Hearts Cards</button>
</li>
<li>
<button id="btnDiamonds">Show Diamonds Cards</button>
</li>
<li>
<button id="btnClubs">Show Clubs Cards</button>
</li>
<li>
<button id="btnSpades">Show Spades Cards</button>
</li>
</ul>
<div id="displayArea">
</div>
</div>
Thank you in advance.