How do you prevent a random number from making an image show twice in a row in jQuery?
There are three arrays that fadeOut and fadeIn.
jQuery code and html code below:
<script type="text/javascript">
jQuery(
function(){
var cardTitle = new Array();
cardTitle[0] = "You've picked Judgment...";
cardTitle[1] = "You've picked the Magician...";
cardTitle[2] = "You've picked Strength...";
cardTitle[3] = "You've picked the High Priestess...";
cardTitle[4] = "You've picked the World...";
var cardDesc = new Array();
cardDesc[0] = "Judgment tells...";
cardDesc[1] = "The Magician generally...";
cardDesc[2] = "Strength is the rawest...";
cardDesc[3] = "Your identification...";
cardDesc[4] = "The World is...";
var drawCard = new Array();
drawCard[0] = "judgement.jpg";
drawCard[1] = "magician.jpg";
drawCard[2] = "strength.jpg";
drawCard[3] = "theHighPriestess.jpg";
drawCard[4] = "theWorld.jpg";
$("#myBtn").click(
function(){
var drawNum = Math.floor(Math.random() * cardTitle.length);
$("h3").fadeOut(
function(){
$("#newTitle").html(cardTitle[drawNum]).fadeIn();
});
$("p").fadeOut(
function(){
$("#newDesc").html(cardDesc[drawNum]).fadeIn();
});
$("img").fadeOut(
function(){
$("#showImage").attr('src', 'images/' + drawCard[drawNum]).fadeIn();
});
} //end click function
); //end click
}); //end jQuery container
</script>
<body>
<img src="images/drawCard.jpg" id="showImage">
<input type = "button" id="myBtn" value="Click Here to Pick a Card" />
<h3 id="newTitle">Welcome to Madam Athena's Tarot Card Reading</h3>
<p id="newDesc">Free your mind...</p>
</body>