Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help me finish my code, Draw Card button will display 5 randomly selected

ID: 3536141 • Letter: P

Question

Please help me finish my code, Draw Card button will display

5

randomly selected cards

and total text box will display the total values of the

cards.

also i need a flush counter,

which counts everytime you get a flush.(all cards same type)

before you click draw it must show 5 cards with picture of

their

backs

card pictures are in the same folder

with

the index file, and their names are like

for hearts:> card1h.jpg ,

card2h.jpg,

card3h.jpg...

for spades:> card1s.jpg,

card2s.jpg,

card3s.jpg...

for club:> card1c.jpg,

card2c.jpg,

card3c.jpg...

for diamonds:> card1d.jpg,

card2d.jpg,

card3d.jpg...

<html>
<head>
<meta charset = "utf-8">
<title>Random Dice Images</title>
<style type = "text/css">
li { display: inline; margin-right: 10px; }
ul { margin: 0; }
</style>
<script>
// variables used to interact with the img elements
var card1Image;
var card2Image;
var card3Image;
var card4Image;
var card5Image;
var Cards = new Array(52);
var total =0;

// register button listener and get the img elements
function start()
{

var button = document.getElementById( "drawCards" );
button.addEventListener( "click",startDraw, false );
card1Image = document.getElementById( "card1" );
card2Image = document.getElementById( "card2" );
card3Image = document.getElementById( "card3" );
card4Image = document.getElementById( "card4" );
card5Image = document.getElementById("card5");

assignCards();
var total =0;

} // end function start


function startDraw(){
total=0;
shuffle();
drawFlush();
}

// Assign the cards to array cards and shuffle
function assignCards()
{
for(var i = 0;i<13;++i)
Cards[i]="card"+(i+1)+"h";
for(var i = 13;i<26;++i)
Cards[i]="card"+(i-12)+"c";
for(var i = 26;i<39;++i)
Cards[i]="card"+(i-23)+"s";
for(var i = 39;i<52;++i)
Cards[i]="card"+(i-34)+"d";

}

// Shuffle the cards
function shuffle(){
for(var i=0;i<53;++i)
{
var temp= Cards[i]
Cards[i]=Cards[j]
Cards[i]=temp;
}
}


// roll the dice
function drawFlush()
{
while(!isFlush())
{



total++;
shuffle();

setImage( card1Image , 0 );
setImage( card2Image , 1 );
setImage( card3Image , 2 );
setImage( card4Image, 3 );
setImage( card5Image , 4);


}

document.getElementById("total").value=total;
} // end function drawFlush


// check for flush
function isFlush()
{
var suit=Cards[0].charAt(Cards[0].length()-1)
var suit=new Array(5);
for (var i=0;i<5;++i)
suit[i]=cards[i].charAt(Cards[i].length()-1);
var s = suite[0];
for (var i=1;i<5;++i)
if (s != suite[i])
{
return false;
}
else{
return true;
}

}
// set src and alt width height attributes for a card
function setImage( cardImg , i )
{
CardImage.setAttribute("/project14/","card"+Cards.value+".jpg");
return Cards.value;
} // end function setImage

window.addEventListener("load",start,false);
</script>
</head>
<body>

<ol>
<li>
<img id = "card1" src="card.jpg" alt = "blank image"></li>
<li>
<img id = "card2" src="card.jpg" alt = "blank image"></li>
<li>
<img id = "card3" src="card.jpg" alt = "blank image"></li>
<li>
<img id = "card4" src="card.jpg" alt = "blank image"></li>
<li>
<img id = "card5" src="card.jpg" alt = "blank image"></li>
</ol>

<form action = "#">
<input id = "drawCards" type = "button" value = "Draw Flush">
<label>Count:<input type="text" id = "total" ></label>
</form>

</body>
</html>



Explanation / Answer

wait

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote