Programming Challenge

You are required to add comments to the following JavaScript program.

This program is a non-modular version of the Nim game program that we looked at earlier in the course.

Copy and paste all of the text below into a suitable text editor.

Note: Make sure that the quotation marks copy correctly to the editor. If they do not delete them and add your own using the text editing software.

<html>
<head>
<script>

var Total = 0 ;
var Number = 0 ;
var GameOver = false ;

Total = prompt ('Enter a starting value: ') ;

while (GameOver == false)
{
if ((Total % 3) == 2)
{
Total = Total - 2 ;
alert ('Computer subtracted 2 from total. Total is now ' + Total) ;
}
else
{
Total = Total - 1 ;
alert ('Computer subtracted 1 from total. Total is now ' + Total) ;
}

if (Total == 0)
{
alert ('The computer wins!') ;
GameOver = true ;
}

if (GameOver == false)
{
Number = prompt ('The total is : ' + Total + '\n' + 'How many do you want to subtract?') ;

while (Number < 1 || Number > 2)
{
Number = prompt ('You can only enter 1 OR 2. Try again') ;
}

Total = Total - Number ;

if (Total == 0)
{
alert ('The player wins!') ;
GameOver = true ;
}
}
}
alert ('Thanks for playing') ;

</script>
</head>
<body>
</body>
</html>

Next: Technical Guide