!!!!!!!!!!!!!what the problem in my BLACK JACK game?

A

aries.ming

This is a homework
but
I don't know how to let it work.
Can U help me?

<html>
<head>
<title>Black Jack</title>


<script type = "text/javascript">


var betValue=0, cashValue = 5000, count1 = 0, count2 = 0,
count3
= 0;


var poker = new Array(52);
var point = new Array(52);
var computerpoint = 0;
var playerpoint = 0;
var numPoker = 0;
var ptime = 0;
var ctime = 0;
var rest = 0;
var tcpoint = 0;
var cscard;
for(var p=0; p<52; p++)
{
poker[p] = p;
}


function shuffle()
{
dealCard.disabled = true;
continueCard.disabled = true;
stopHere.disabled = true;
numPoker = 0;
for(var r=0; r<=1000; r++)
{
x = Math.floor(Math.random()*52);
y = Math.floor(Math.random()*52);
var temp;


temp = poker[x];
poker[x] = poker[y];
poker[y] = temp;
}
for(var i=0; i<52; i++)
{
point = poker%13 + 1;


if (point >= 10)
point = 10;
}
rest = 52 - numPoker;
numRest.innerHTML = rest;
Cash.innerHTML = cashValue;
Bet.innerHTML = betValue;
}


function look()
{
var takeLook;
takeLook = window.open();


takeLook.document.writeln("<table border = \"1\">");
takeLook.document.writeln("<tbody>");
for(var i=0; i<=3; i++)
{
takeLook.document.writeln("<tr>");
for(var k=0; k<13; k++)
{
takeLook.document.writeln("<td align =
center>" + (k+1+i*13) + "</
td>");
}
takeLook.document.writeln("</tr>");
takeLook.document.writeln("<tr>");
for(var j=0; j<13; j++)
{
takeLook.document.writeln("<td><img src = "C:
\Documents and Settings
\ariesming\×ÀÃæ\Pokers"+ poker[j+i*13] +".png"></td>");
}
takeLook.document.writeln("</tr>");
}
takeLook.document.writeln("</tbody>");
takeLook.document.writeln("</table>");
}


function deal()
{
dealCard.disabled = false;
continueCard.disabled = true;
player[0].innerHTML = "<img src = "C:\Documents and Settings
\ariesming
\×ÀÃæ\Pokers" + poker[numPoker] + ".png">";
playerpoint = point[numPoker];
numPoker++;
computer[0].innerHTML = "<img src = "C:\Documents and
Settings
\ariesming\×ÀÃæ\Pokers\back1.png">";
tcpoint = point[numPoker];
cscard = numPoker;
numPoker++;
player[1].innerHTML = "<img src = "C:\Documents and Settings
\ariesming
\×ÀÃæ\Pokers" + poker[numPoker] + ".png">";
playerpoint += point[numPoker];
numPoker++;
computer[1].innerHTML = "<img src = "C:\Documents and
Settings
\ariesming\×ÀÃæ\Pokers" + poker[numPoker] + ".png">";
computerpoint = point[numPoker];
tcpoint += point[numPoker];
numPoker++;
ppoint.innerHTML = playerpoint;
cpoint.innerHTML = computerpoint;
rest = 52 - numPoker;
numRest.innerHTML = rest;
}


function continue()
{
player[2+ptime].innerHTML = "<img src = "C:\Documents and
Settings
\ariesming\×ÀÃæ\Pokers" + poker[numPoker] + ".png">";
playerpoint += point[numPoker];
ppoint.innerHTML = playerpoint;
numPoker++;
ptime++;
if((playerpoint >= 21) || (ptime >= 3))
{
continueCard.disabled = true;
stop();
}
rest = 52 - numPoker;
numRest.innerHTML = rest;
}


function stop()
{
computer[0].innerHTML = "<img src = "C:\Documents and
Settings
\ariesming\×ÀÃæ\Pokers" + poker[cscard] + ".png">";
if(ptime = 3)
{
cpoint.innerHTML = tcpoint;
newGame.disabled = false;
win();
}
else
{
while((tcpoint < playerpoint) && (playerpoint <=21))
{
computer[2+ctime].innerHTML = "<img src = "C:
\Documents and Settings
\ariesming\×ÀÃæ\Pokers" + poker[numPoker] + ".png">";
computerpoint += point[numPoker];
tcpoint += point[numPoker];
/*abc.innerHTML = "tcpoint";*/
numPoker++;
ctime++;
rest = 52 - numPoker;
numRest.innerHTML = rest;
}
cpoint.innerHTML = tcpoint;
newGame.disabled = false;
win();
}
}


function newgame()
{
ptime = 0;
ctime = 0;
rest = 0;
playerpoint = 0;
computerpoint = 0;
tcpoint = 0;
for( var i=0; i<5; i++)
{
player.innerHTML = "";
computer.innerHTML = "";
}
ppoint.innerHTML = "0";
cpoint.innerHTML = "0";
dealCard.disabled = false;
newGame.disabled = true;
}


function win()
{
if ((playerpoint <= 21) && (ptime = 3))
alert("You win!!!");
else if ((tcpoint <=21) && (ctime = 3))
alert("You lose!!!");
else if (playerpoint > tcpoint)
alert("You win!!");
else if (playerpoint < tcpoint)
alert("You lose!!");
else
alert("Draw!");
}


function bet100()
{
betValue += 100;
cashValue -= 100;
Cash.innerHTML = cashValue;
Bet.innerHTML = betValue;
count1 ++;
if (count1 >= 3) Bet100.disabled = true;
deal();
}


function bet10()
{
betValue += 10;
cashValue -= 10;
Cash.innerHTML = cashValue;
Bet.innerHTML = betValue;
count2 ++;
if (count2 >= 3) Bet10.disabled = true;
deal();
}


function bet1()
{
betValue += 1;
cashValue -= 1;
Cash.innerHTML = cashValue;
Bet.innerHTML = betValue;
count3 ++;
if (count3 >= 3) Bet1.disabled = true;
deal();
}


</script>
</head>


<body bgcolor = "pink" onload = "shuffle()">


<table width = "80%">
<colgroup>
<col span = "2" />
</colgroup>


<thead>
<tr>
<th colspan = "2" width = "60%" align = "left" valign =
"top"> <h2>Computer</h2></br></th>
<th align = "left" valign = "top" colspan = "2" id =
"cpoint" id = "abc"> <h2></h2> </th>
<td height = "170" valign = middle id = "computer[0]"></td>
<td height = "170" valign = middle id = "computer[1]"></td>
<td height = "170" valign = middle id = "computer[2]"></td>
<td height = "170" valign = middle id = "computer"></td>
<td height = "170" valign = middle id = "computer"></td>
</tr>


<tr>
<th colspan = "2" rowspan = "2" align = "left" valign =
"top"><h2>Player</h2></br>
<th align = "left" valign = "top" colspan = "2" id =
"ppoint"><h2></h2></th>
<td height = "99" valign = middle id = "player"></td>
<td height = "99" valign = middle id = "player"></td>
<td height = "99" valign = middle id = "player"></td>
<td height = "99" valign = middle id = "player"></td>
<td height = "99" valign = middle id = "player"></td>
<td height = "99" valign = middle id = "player"></td>
</tr>


<tr>
<th align = "left" colspan = "2">
<input id = "dealCard" type = "button" value = "°lÅÆ" onclick
= "deal()"/></br>
<input id = "continueCard" type = "button" value = "ÑaÅÆ"
onclick = "continue()" disabled = "disabled"/></br>
<input id = "stopHere" type = "button" value = "Í£Ö¹" onclick
= "stop()" disabled = "disabled"/></th>
</tr>
</thead>


<tbody>
<tr>
<th align = "midiem" width = "30%" height = "50">Cash</th>
<th align = "left" id = "Cash">5000</th>
<th width = "10%">Ê£ðNÅÆ”µ£º</th>
<th align = "left" id = "numRest">52</th>
</tr>


<tr>
<th align = "midiem" width = "30%" height = "50">Bet</th>
<th align = "left" id = "Bet">0</th>
<th align = "left" colspan = "2"><input id = "Bet100" type
= "button" value = "100" onclick = "bet100()"/>
<input id = "Bet10" type = "button" value = "10"
onclick
= "bet10()"/>
<input id = "Bet1" type = "button" value = "1" onclick
=
"bet1()"/></br>
You can press each button for at most three times.</th>
</tr>


<tr>
<th colspan = "4" height = "50" align = "left">
<input id = "newGame" type = "button" value = "ÐÂß[‘ò"
onclick = "new()" />
<input id = "shuffleCard" type = "button" value = "Ï´ÅÆ"
onclick = "shuffle()"/>
<input id = "lookCard" type = "button" value = "Ó^¿´ËùÓÐÅÆ"
onclick = "look()"/></th>
</tr>
</tbody>
</body>
</html>
 
G

GArlington

This is a homework
but
I don't know how to let it work.
Can U help me?

<html>
<head>
<title>Black Jack</title>

<script type = "text/javascript">

var betValue=0, cashValue = 5000, count1 = 0, count2 = 0,
count3
= 0;

var poker = new Array(52);
var point = new Array(52);
var computerpoint = 0;
var playerpoint = 0;
var numPoker = 0;
var ptime = 0;
var ctime = 0;
var rest = 0;
var tcpoint = 0;
var cscard;
for(var p=0; p<52; p++)
{
poker[p] = p;
}

function shuffle()
{
dealCard.disabled = true;
continueCard.disabled = true;
stopHere.disabled = true;
numPoker = 0;
for(var r=0; r<=1000; r++)
{
x = Math.floor(Math.random()*52);
y = Math.floor(Math.random()*52);
var temp;

temp = poker[x];
poker[x] = poker[y];
poker[y] = temp;
}
for(var i=0; i<52; i++)
{
point = poker%13 + 1;

if (point >= 10)
point = 10;
}
rest = 52 - numPoker;
numRest.innerHTML = rest;
Cash.innerHTML = cashValue;
Bet.innerHTML = betValue;
}

function look()
{
var takeLook;
takeLook = window.open();

takeLook.document.writeln("<table border = \"1\">");
takeLook.document.writeln("<tbody>");
for(var i=0; i<=3; i++)
{
takeLook.document.writeln("<tr>");
for(var k=0; k<13; k++)
{
takeLook.document.writeln("<td align =
center>" + (k+1+i*13) + "</
td>");
}
takeLook.document.writeln("</tr>");
takeLook.document.writeln("<tr>");
for(var j=0; j<13; j++)
{
takeLook.document.writeln("<td><img src = "C:
\Documents and Settings
\ariesming\×ÀÃæ\Pokers"+ poker[j+i*13] +".png"></td>");
}
takeLook.document.writeln("</tr>");
}
takeLook.document.writeln("</tbody>");
takeLook.document.writeln("</table>");
}

function deal()
{
dealCard.disabled = false;
continueCard.disabled = true;
player[0].innerHTML = "<img src = "C:\Documents and Settings
\ariesming
\×ÀÃæ\Pokers" + poker[numPoker] + ".png">";
playerpoint = point[numPoker];
numPoker++;
computer[0].innerHTML = "<img src = "C:\Documents and
Settings
\ariesming\×ÀÃæ\Pokers\back1.png">";
tcpoint = point[numPoker];
cscard = numPoker;
numPoker++;
player[1].innerHTML = "<img src = "C:\Documents and Settings
\ariesming
\×ÀÃæ\Pokers" + poker[numPoker] + ".png">";
playerpoint += point[numPoker];
numPoker++;
computer[1].innerHTML = "<img src = "C:\Documents and
Settings
\ariesming\×ÀÃæ\Pokers" + poker[numPoker] + ".png">";
computerpoint = point[numPoker];
tcpoint += point[numPoker];
numPoker++;
ppoint.innerHTML = playerpoint;
cpoint.innerHTML = computerpoint;
rest = 52 - numPoker;
numRest.innerHTML = rest;
}

function continue()
{
player[2+ptime].innerHTML = "<img src = "C:\Documents and
Settings
\ariesming\×ÀÃæ\Pokers" + poker[numPoker] + ".png">";
playerpoint += point[numPoker];
ppoint.innerHTML = playerpoint;
numPoker++;
ptime++;
if((playerpoint >= 21) || (ptime >= 3))
{
continueCard.disabled = true;
stop();
}
rest = 52 - numPoker;
numRest.innerHTML = rest;
}

function stop()
{
computer[0].innerHTML = "<img src = "C:\Documents and
Settings
\ariesming\×ÀÃæ\Pokers" + poker[cscard] + ".png">";
if(ptime = 3)
{
cpoint.innerHTML = tcpoint;
newGame.disabled = false;
win();
}
else
{
while((tcpoint < playerpoint) && (playerpoint <=21))
{
computer[2+ctime].innerHTML = "<img src = "C:
\Documents and Settings
\ariesming\×ÀÃæ\Pokers" + poker[numPoker] + ".png">";
computerpoint += point[numPoker];
tcpoint += point[numPoker];
/*abc.innerHTML = "tcpoint";*/
numPoker++;
ctime++;
rest = 52 - numPoker;
numRest.innerHTML = rest;
}
cpoint.innerHTML = tcpoint;
newGame.disabled = false;
win();
}
}

function newgame()
{
ptime = 0;
ctime = 0;
rest = 0;
playerpoint = 0;
computerpoint = 0;
tcpoint = 0;
for( var i=0; i<5; i++)
{
player.innerHTML = "";
computer.innerHTML = "";
}
ppoint.innerHTML = "0";
cpoint.innerHTML = "0";
dealCard.disabled = false;
newGame.disabled = true;
}

function win()
{
if ((playerpoint <= 21) && (ptime = 3))
alert("You win!!!");
else if ((tcpoint <=21) && (ctime = 3))
alert("You lose!!!");
else if (playerpoint > tcpoint)
alert("You win!!");
else if (playerpoint < tcpoint)
alert("You lose!!");
else
alert("Draw!");
}

function bet100()
{
betValue += 100;
cashValue -= 100;
Cash.innerHTML = cashValue;
Bet.innerHTML = betValue;
count1 ++;
if (count1 >= 3) Bet100.disabled = true;
deal();
}

function bet10()
{
betValue += 10;
cashValue -= 10;
Cash.innerHTML = cashValue;
Bet.innerHTML = betValue;
count2 ++;
if (count2 >= 3) Bet10.disabled = true;
deal();
}

function bet1()
{
betValue += 1;
cashValue -= 1;
Cash.innerHTML = cashValue;
Bet.innerHTML = betValue;
count3 ++;
if (count3 >= 3) Bet1.disabled = true;
deal();
}

</script>
</head>

<body bgcolor = "pink" onload = "shuffle()">

<table width = "80%">
<colgroup>
<col span = "2" />
</colgroup>

<thead>
<tr>
<th colspan = "2" width = "60%" align = "left" valign =
"top"> <h2>Computer</h2></br></th>
<th align = "left" valign = "top" colspan = "2" id =
"cpoint" id = "abc"> <h2></h2> </th>
<td height = "170" valign = middle id = "computer[0]"></td>
<td height = "170" valign = middle id = "computer[1]"></td>
<td height = "170" valign = middle id = "computer[2]"></td>
<td height = "170" valign = middle id = "computer"></td>
<td height = "170" valign = middle id = "computer"></td>
</tr>

<tr>
<th colspan = "2" rowspan = "2" align = "left" valign =
"top"><h2>Player</h2></br>
<th align = "left" valign = "top" colspan = "2" id =
"ppoint"><h2></h2></th>
<td height = "99" valign = middle id = "player"></td>
<td height = "99" valign = middle id = "player"></td>
<td height = "99" valign = middle id = "player"></td>
<td height = "99" valign = middle id = "player"></td>
<td height = "99" valign = middle id = "player"></td>
<td height = "99" valign = middle id = "player"></td>
</tr>

<tr>
<th align = "left" colspan = "2">
<input id = "dealCard" type = "button" value = "°lÅÆ" onclick
= "deal()"/></br>
<input id = "continueCard" type = "button" value = "ÑaÅÆ"
onclick = "continue()" disabled = "disabled"/></br>
<input id = "stopHere" type = "button" value = "Í£Ö¹" onclick
= "stop()" disabled = "disabled"/></th>
</tr>
</thead>

<tbody>
<tr>
<th align = "midiem" width = "30%" height = "50">Cash</th>
<th align = "left" id = "Cash">5000</th>
<th width = "10%">Ê£ðNÅÆ”µ£º</th>
<th align = "left" id = "numRest">52</th>
</tr>

<tr>
<th align = "midiem" width = "30%" height = "50">Bet</th>
<th align = "left" id = "Bet">0</th>
<th align = "left" colspan = "2"><input id = "Bet100" type
= "button" value = "100" onclick = "bet100()"/>
<input id = "Bet10" type = "button" value = "10"
onclick
= "bet10()"/>
<input id = "Bet1" type = "button" value = "1" onclick
=
"bet1()"/></br>
You can press each button for at most three times.</th>
</tr>

<tr>
<th colspan = "4" height = "50" align = "left">
<input id = "newGame" type = "button" value = "ÐÂß[‘ò"
onclick = "new()" />
<input id = "shuffleCard" type = "button" value = "Ï´ÅÆ"
onclick = "shuffle()"/>
<input id = "lookCard" type = "button" value = "Ó^¿´ËùÓÐÅÆ"
onclick = "look()"/></th>
</tr>
</tbody>
</body>
</html>


You got quite a lot of it right, but, did you try to create an html
file and open it in your browser (IE or FF...)
What happens when you do? I suspect you will see messages refering to
javascript errors. This is because javascript is (nearly) a
programming language, it needs to know what you want to do and what
you want these actions to apply to. What you do is represented by
functions and what you apply these actions to is represented by
variables. The variables need to be set to point to correct items/
objects before you can use them or apply actions to them.
If you use FF (Firefox) it comes with error console and you can
download FireBug (Add-on) - very useful for debugging javascripts.
 
D

Dr J R Stockton

In comp.lang.javascript message <76e18961-d116-4b7e-b940-5d82ac7f8531@i1
2g2000prf.googlegroups.com>, Wed, 5 Dec 2007 00:00:09,
(e-mail address removed) posted:
for(var r=0; r<=1000; r++)
{
x = Math.floor(Math.random()*52);
y = Math.floor(Math.random()*52);
var temp;


temp = poker[x];
poker[x] = poker[y];
poker[y] = temp;
}

That is grossly inefficient; see what the FAQ says.

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top