I have a web page that shows four buttons, one for each suit in a deck of cards. When a user clicks on a button, it should show the card image of that suit, starting with Ace, 2, 3, etc. through King. The first card should show for three seconds, then be replaced by the next card for three seconds, etc. Here is my HTML:
<!DOCTYPE html>
<html>
<head>
<title>jQuery Assignment 4 - Cards</title>
<link href="styles/my_style.css" rel="stylesheet">
</head>
<body>
<div id="main">
<h1>Click a suit to reveal a card</h1>
<div id="my_hand">
<img src="images/hit_small.jpg" id="cardBack">
</div>
<div id="controls">
<div id="btnHearts">
<button>Hearts</button>
</div>
<div id="btnDiamonds">
<button>Diamonds</button>
</div>
<div id="btnClubs">
<button>Clubs</button>
</div>
<div id="btnSpades">
<button>Spades</button>
</div>
</div>
</div>
<script src="scripts/jquery-1.6.2.min.js"></script>
<script src="scripts/my_scripts.js"></script>
</body>
</html>
Here is the CSS:
#cardBack {
float: left;
}
#cardFront {
float: right;
}
h1 {
text-align: center;
}
#my_hand{
clear: both;
border: 1px solid gray;
height: 245px;
width: 350px;
margin: auto;
}
#controls {
width: 100%;
float: left;
text-align: center;
margin-top: 50px;
}
#btnHearts, #btnDiamonds, #btnClubs, #btnSpades{
text-align: center;
display: inline-block;
padding: 20px;
}
Here is my javascript:
$(document).ready(function(){
function card(name,suit,value) {
this.name = name;
this.suit = suit;
this.value = value;
};
var old_cards = new Array();
var hearts = [
new card('Ace', 'Hearts',1),
new card('Two', 'Hearts',2),
new card('Three', 'Hearts',3),
new card('Four', 'Hearts',4),
new card('Five', 'Hearts',5),
new card('Six', 'Hearts',6),
new card('Seven', 'Hearts',7),
new card('Eight', 'Hearts',8),
new card('Nine', 'Hearts',9),
new card('Ten', 'Hearts',10),
new card('Jack', 'Hearts',10),
new card('Queen', 'Hearts',10),
new card('King', 'Hearts',10)
];
var diamonds = [
new card('Ace', 'Diamonds',1),
new card('Two', 'Diamonds',2),
new card('Three', 'Diamonds',3),
new card('Four', 'Diamonds',4),
new card('Five', 'Diamonds',5),
new card('Six', 'Diamonds',6),
new card('Seven', 'Diamonds',7),
new card('Eight', 'Diamonds',8),
new card('Nine', 'Diamonds',9),
new card('Ten', 'Diamonds',10),
new card('Jack', 'Diamonds',10),
new card('Queen', 'Diamonds',10),
new card('King', 'Diamonds',10)
];
var clubs = [
new card('Ace', 'Clubs',1),
new card('Two', 'Clubs',2),
new card('Three', 'Clubs',3),
new card('Four', 'Clubs',4),
new card('Five', 'Clubs',5),
new card('Six', 'Clubs',6),
new card('Seven', 'Clubs',7),
new card('Eight', 'Clubs',8),
new card('Nine', 'Clubs',9),
new card('Ten', 'Clubs',10),
new card('Jack', 'Clubs',10),
new card('Queen', 'Clubs',10),
new card('King', 'Clubs',10)
];
var spades = [
new card('Ace', 'Spades',1),
new card('Two', 'Spades',2),
new card('Three', 'Spades',3),
new card('Four', 'Spades',4),
new card('Five', 'Spades',5),
new card('Six', 'Spades',6),
new card('Seven', 'Spades',7),
new card('Eight', 'Spades',8),
new card('Nine', 'Spades',9),
new card('Ten', 'Spades',10),
new card('Jack', 'Spades',10),
new card('Queen', 'Spades',10),
new card('King', 'Spades',10)
];
var hand = {
cards : new Array(),
};
$("#btnHearts").click(function(){
var index = $.inArray(index, hearts);
do {
//Show a new card every 3 seconds, starting with the Ace, then 2, 3, etc...
}while {
}
var c = hearts[ index ];
old_cards[old_cards.length] = index;
hand.cards[hand.cards.length] = c;
var $i = $("<img>");
$i.addClass("current_hand")
.appendTo("#my_hand");
$("<img>").attr('id', 'cardFront')
.attr('alt', c.name + ' of ' + c.suit )
.attr('title', c.name + ' of ' + c.suit )
.attr('src', 'images/cards/' + c.suit + '/' + c.name + '.jpg' )
.appendTo($i);
});
});
I'm pretty lost on this one. I know I want to start the index at 0 for the Ace, the loop through each one while setting a timer of three seconds. Any help is very much appreciated!