if a player clicks on the take card button, it generates a random number between 0 and 10 and is added to the player's score. if the player's score goes over 21, then player loses and shows an alert message saying player lost and also put a loss count as minus one.
if a player clicks on the done button, it generates a random number between 0 and 10 and it is added to the poopnent's score. numbers continue to be added as long as the opponent has less than 17.
if the opponent goves over 21, the opponent loses. once the opponent has more than 16, the scores of the player and the opponent are compared and if player wins, then show an alert message saying player won and vice versa. if player wins, then +1 to the stats, and if player loses, then -1 to the stats.
and I think I have all the code to execute this game, but it seems that I have a minor error or some little letter or symbol missing that I cannot find. Its a little frustrating since there is no debugger for javascript. Can someone debug my errors, and can you also tell me what program you use to do javascript coding and what program if there is any to debug your code. Thanks.
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
<title>Project_01</title>
</head>
<body bgcolor="#FFFFFF">
<script language="JavaScript">
<!--
function takeCard()
{
var stats = winsBox.value = 0;
var score = myBox.value = 0;
score = score + Math.round(Math.random() * 9) + 1;
if(score > 21)
{
resultBox.value = "You Lost.";
DoneButton.disabled = true;
CardButton.disabled = true;
stats = stats - 1;
}
}
function done()
{
var stats = winsBox.value = 0;
var score = myBox.value = 0;
var opscore = 0;
while(opscore > 16);
{
opscore = opscore + Math.round(Math.random() * 9) + 1;
}
if(opscore > 21)
{
resultBox.value = "Opponent Lost.";
stats = stats + 1;
}
else if(opscore <= 21 && score > opscore)
{
resultBox.value = "You Won.";
stats = stats + 1;
}
}
function playAgain()
{
var stats = winsBox.value = 0;
var score = myBox.value = 0;
score = 0;
opscore = 0;
resultBox.value = "";
DoneButton.disabled = false;
CardButton.disabled = false;
}
//-->
</script>
<p align="center"><font color="#FF0000" size="6">Game of 21</font></p>
<p align="center"><font size="4">Opponent<br>
<input type="text" size="20" name="opponentBox"></font></p>
<p align="center"><font size="4">You<br>
<input type="text" size="20" name="myBox"></font></p>
<p align="center">
<input type="button" name="CardButton"
value="Take a Card" onclick="if(score<21) {takeCard()};">
<input type="button" name="DoneButton"
value="Done" onclick="done()">
<input type="button" name="AgainButton"
value="Play Again"
onclick="playAgain()"></p>
<p align="center"><font size="4">Result <input type="text"
size="24" name="resultBox"></font></p>
<p align="center"><font size="4">Score <input type="text"
size="4" name="winsBox"></font></p>
</body>
</html>
Edited by lee890910, 25 May 2006 - 11:01 AM.
