Javascript : Pontoon Project

Associate
Joined
18 Jan 2006
Posts
8
As the title says im trying to create a Javascript program that allows the user to play pontoon. I have got this far and have got stuck on an error I cant see.

Please keep explinations simple as im very new to java script. :D

Thanks.

<HTML>
<HEAD>
<SCRIPT LANUAGE = "javascript">


function stick_option ()
// This will ask the player if they wish to stick or not

{

var playerans = 0;

playerans = prompt('Do you with to continue?', Y/N?);
if (playerans = Y)
counter = (counter + decounter);




}


function bust_teller ()
//This is a function to tell the player they are bust

{

alert('Your cards have exceded 21 - Your Bust');
counter = (counter + decounter);

}

function main_function ()
//This is a function to add 5 playing cards and add up the total

{



var cardtotal = 0;
var cardout = 0;
var counter = 0;
var decounter = 0;

while (counter < 5)
{

cardtotal = prompt('Enter your five cards -', 0);
counter = counter + 1
decounter = decounter + 5
decounter = decounter - 1
cardout = cardout * 1 + cardtotal * 1;

{if (cardout > 21)
alert('Your cards have exceded 21 - Your Bust');
bust_teller () }


else

if (cardout < 16)
alert('Your hand is high enough to stick on')
stick_option ()



}





alert ('Your hand is ' + cardout);

}


</SCRIPT>
</HEAD>
<BODY>
<FORM NAME = "my form">
<center>

<P>Pontoon</P>
<p>You will be asked to input the cards you have been dealt</p>
<input type = "button" VALUE = "Start"
onClick = "main_function () ;">
</center>

</FORM>
</BODY>
</HTML>
 
can't remember what i fixed, but I'll let you compare it to what you have now.

It's not finished for you, but ive fixed your syntax errors so it will at least now run.

Code:
<HTML>
<HEAD>
	<SCRIPT LANGUAGE="javascript">
		function stick_option() {
			// This will ask the player if they wish to stick or not
			var playerans = 0;

			playerans = prompt("Do you with to continue?", "");
			if (playerans = Y)
			counter = (counter + decounter);
		}

		function bust_teller() {
			//This is a function to tell the player they are bust
			alert('Your cards have exceded 21 - Your Bust');
			counter = (counter + decounter);
		}

		function main_function() {
			//This is a function to add 5 playing cards and add up the total
			var cardtotal = 0;
			var cardout = 0;
			var counter = 0;
			var decounter = 0;

			while (counter < 5) {
				cardtotal = prompt('Enter your five cards -', 0);
				counter = counter + 1
				decounter = decounter + 5
				decounter = decounter - 1
				cardout = cardout * 1 + cardtotal * 1;

				if (cardout > 21) {
				alert('Your cards have exceded 21 - Your Bust');
				bust_teller () }
				else {

					if (cardout < 16) {
						alert('Your hand is high enough to stick on')
						stick_option ()
					}
				}
			}			
			alert ('Your hand is ' + cardout);
		}
	</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="myform">
<center>

<P>Pontoon</P>
<p>You will be asked to input the cards you have been dealt</p>
<input type="button" VALUE="Start" onclick="main_function()">
</center>

</FORM>
</BODY>
</HTML>
HTH!
 
You need to play with your IF statements a bit. For example:

Code:
playerans = prompt("Do you with to continue?", "");
			if (playerans = Y)
			counter = (counter + decounter);

First thing is that in an IF statement you need to use a double equals sign. Reason is that in JS a single equals sign means 'make equal to' where a double equals sign means 'is equal to'.

So this is right:
Code:
			counter = (counter + decounter);
But this is wrong:
Code:
		   if (playerans = Y)

Also, the action which you want to carry out if the IF statement is true should be in curly brackets.

So the code for the above would be:

Code:
playerans = prompt("Do you with to continue?", "");
if (playerans == Y) {
counter = (counter + decounter);
}

Hope this helps :)
 
Thanks that was very helpful.

Im able to to allow the user to stop the loop, but how can I force the loop to start again if the user wants to keep playing?
 
Back
Top Bottom