sparhavk

06-29-2010, 06:30 AM

Hello all,

I’ve got a homework to do and I'm stuck, as you can see i have done all the function's (i think they are ok but not shure) with a main program I'm stuck don’t know even where to begin :/ could anyone please please help a bit?

best regards

<HTML>

<HEAD>

<TITLE>

The game of 21

</TITLE>

<SCRIPT LANGUAGE = "JavaScript">

//FUNCTIONS

/*

*removes a given number of sticks

*

*function takes one argument numberToRemove that represents the number of sticks to be removed

* if numberToRemove is more than numberOfSticks, reduces numberOfSticks to 0

* otherwise reduces numberOfSticks by numberToRemove

*function returns no value

*/

function removeSticks(numberToRemove)

{

if (numberOfSticks< numberToRemove)

{

numberOfSticks =0

}

else

{

(numberOfSticks = numberOfSticks - numberToRemove);

}

}

/*

*switches current player

*

*function takes no argument

* if current player is 1, sets current player to 2

* otherwise sets current player to 1

*function returns no value

*/

function switchCurrentPlayer()

{

if (currentPlayer ==1)

{

return currentPlayer = 2;

}

{

return currentPlayer = 1;

}

}

/*

*gets a number from a prompt dialogue

*

*function takes no argument

* prompts the current player for a number of sticks to remove, with a suitable message

*function returns the number the player enters

*/

function getChosenNumber()

{

ChosenNumber = window.prompt('Player ' + currentPlayer + ': Please enter either 1, 2 OR 3.');

return ChosenNumber;

}

//VARIABLES -- do not change this section

var numberOfSticks = 21;//number of matchsticks, initially 21

var currentPlayer = 1;//player whose turn it is, Player 1 goes first

var numberChosen;//variable used to hold the number the current player chooses

//MAIN PROGRAM

The players take turns to choose how many matches to remove, as long as there are still matches left. After each go the program outputs the number of matches that still remain and if this number is zero a message is displayed to say the current player is the winner. The turn then passes to the other player.

</SCRIPT>

</HEAD>

<BODY>

</BODY>

</HTML>

I’ve got a homework to do and I'm stuck, as you can see i have done all the function's (i think they are ok but not shure) with a main program I'm stuck don’t know even where to begin :/ could anyone please please help a bit?

best regards

<HTML>

<HEAD>

<TITLE>

The game of 21

</TITLE>

<SCRIPT LANGUAGE = "JavaScript">

//FUNCTIONS

/*

*removes a given number of sticks

*

*function takes one argument numberToRemove that represents the number of sticks to be removed

* if numberToRemove is more than numberOfSticks, reduces numberOfSticks to 0

* otherwise reduces numberOfSticks by numberToRemove

*function returns no value

*/

function removeSticks(numberToRemove)

{

if (numberOfSticks< numberToRemove)

{

numberOfSticks =0

}

else

{

(numberOfSticks = numberOfSticks - numberToRemove);

}

}

/*

*switches current player

*

*function takes no argument

* if current player is 1, sets current player to 2

* otherwise sets current player to 1

*function returns no value

*/

function switchCurrentPlayer()

{

if (currentPlayer ==1)

{

return currentPlayer = 2;

}

{

return currentPlayer = 1;

}

}

/*

*gets a number from a prompt dialogue

*

*function takes no argument

* prompts the current player for a number of sticks to remove, with a suitable message

*function returns the number the player enters

*/

function getChosenNumber()

{

ChosenNumber = window.prompt('Player ' + currentPlayer + ': Please enter either 1, 2 OR 3.');

return ChosenNumber;

}

//VARIABLES -- do not change this section

var numberOfSticks = 21;//number of matchsticks, initially 21

var currentPlayer = 1;//player whose turn it is, Player 1 goes first

var numberChosen;//variable used to hold the number the current player chooses

//MAIN PROGRAM

The players take turns to choose how many matches to remove, as long as there are still matches left. After each go the program outputs the number of matches that still remain and if this number is zero a message is displayed to say the current player is the winner. The turn then passes to the other player.

</SCRIPT>

</HEAD>

<BODY>

</BODY>

</HTML>