I am not able to figure out how to make this work.
I am trying to create a hangman game. I am in a basic javascripting class.
I am to only use very basic code as you can see. I am able to use any online resources to help me.
I have added alot of comments for what should be happening however is not happening.
I also have a teacher that teaches us one way but then asks us to do things he has not taught. I am trying my very best.
Any help is greatly appreciated!
[HTML]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Hangma n</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript" language="JavaS cript">
var NumberOfChances ;
var theWord = "";
var currentGuessed = "";
//Array of 50 secret words
var words = new Array();
words[0]="computer";
words[1]="electronic ";
words[2]="negative";
words[3]="positive";
words[4]="ambassador ";
words[5]="dictionary ";
words[6]="maintain";
words[7]="responsibl e";
words[8]="adventure" ;
words[9]="sunshine";
words[10]="friendship ";
words[11]="attention" ;
words[12]="surgery";
words[13]="genealogy" ;
words[14]="investment ";
words[15]="mathematic s";
words[16]="journey";
words[17]="interest";
words[18]="moment";
words[19]="military";
words[20]="developmen t";
words[21]="enjoyment" ;
words[22]="encouragement ";
words[23]="hygiene";
words[24]="enlistment ";
words[25]="hyphenatio n";
words[26]="orientatio n";
words[27]="references ";
words[28]="highlight" ;
words[29]="recipients ";
words[30]="envelopes" ;
words[31]="preview";
words[32]="translatio n";
words[33]="research";
words[34]="grammar";
words[35]="thumbnails ";
words[36]="document";
words[37]="position";
words[38]="window";
words[39]="conversation" ;
words[40]="recommendatio ns";
words[41]="experience ";
words[42]="reference" ;
words[43]="failure";
words[44]="dignity";
words[45]="faithfulness" ;
words[46]="recklessness" ;
words[47]="leftovers" ;
words[48]="remainder" ;
words[49]="difficulty ";
words[50]="boxes";
//hangman series of images
var image = new Array();
image[0] = '<img src="images/image0.jpg" align ="left" width="415" height="496">';
image[1] = '<img src="images/image1.jpg" align ="left" width="415" height="496">';
image[2] = '<img src="images/image2.jpg" align ="left" width="415" height="496">';
image[3] = '<img src="images/image3.jpg" align ="left" width="415" height="496">';
image[4] = '<img src="images/image4.jpg" align ="left" width="415" height="496">';
image[5] = '<img src="images/image5.jpg" align ="left" width="415" height="496">';
image[6] = '<img src="images/image6.jpg" align ="left" width="415" height="496">';
document.getEle mentById('Image ').innerHTML = '<img src = "Image' + count + '.jpg" />';
NumberOfChances = image.length;
//swap the images for the hangman, start with image[0], then replace the image with each wrong guess, 6 chances
function swap(image)
{
var content=documen t.getElementByI d("imgID"+image ).src;
}
// an array to store the letters guessed if i can not figure out how to disable onclick of letters in form,
//want to highlight them red to so the player sees that they already choose that letter
var usedLetters = new Array();
for (i=0; i<letterguessed ; i++)
// creating the random pick of the secret word out of 50 choices
function secretWord()
{
theWord = words[Math.floor(Math .random()*51)];
for (i=0; i<theWord.lengt h; i++)
{
currentGuessed = currentGuessed + "*";
}
}
//the process that starts the game and resets it when the player chooses to play again
function gameProcess()
{
currentGuessed ="";
secretWord();
NumberOfChances =0;
startImage = image[0];
while (NumberOfChance s<7)
{
// not here move somewhere
onload= "gameProces s()" //
turn();
}
}
//this is what happens when the player takes a turn
function turn(letterGues sed)
{
var correctGuess = False;
for (i=0; i<theWord.lengt h; i++)
{
if (theWord[i] == letterGuessed)
{
currentGuessed[i] = letterGuessed;
correctGuess=Tr ue;
}
}
if (!correctGuess)
{
NumberOfChances ++;
if (NumberOfChance s==7)
{
alert("You Lost!")
}
if(correctGuess != 0)
{
takeChance();
}
win();
}
}
function win()
{
var winCount = 0;
for(var i = 0;i<word.length ;i++)
{
if(wordDisplay[i] == "*")
{
winCount++;
}
}
if(winCount == 0)
{
document.write( "yay, you win!");
}
}
</script>
</head>
<body>
<!--need to use Div tags -->
<H1> Hang De Clown</H1>
<!--hangman pic displaying first image, need to swap images with each wrong guess -->
<div id=Image><img src='images/image0.jpg' align ="left" width="415" height="496"></div>
<div id="wordDisplay "></div>
<!-- form for guessing letter,display secret word, display number of guesses left, restart, end game -->
<form name="userGuess Form">
This is the Secret Word<br /><input id="secretWord " type=text value="currentG uessed" />
<br />
<input id="letters" type="button" name="a" value="a" onClick="turn(' a');"><!-- as player guess wrong letter change to red and make unusable so player can not choose the letter again-->
<input id="letters" type="button" name="b" value="b" onClick="turn(' b');">
<input id="letters" type="button" name="c" value="c" onClick="turn(' c');">
<input id="letters" type="button" name="d" value="d" onClick="turn(' d');">
<input id="letters" type="button" name="e" value="e" onClick="turn(' e');">
<input id="letters" type="button" name="f" value="f" onClick="turn(' f');">
<input id="letters" type="button" name="g" value="g" onClick="turn(' g');">
<input id="letters" type="button" name="h" value="h" onClick="turn(' h');">
<input id="letters" type="button" name="i" value="i" onClick="turn(' i');">
<input id="letters" type="button" name="j" value="j" onClick="turn(' j');">
<input id="letters" type="button" name="k" value="k" onClick="turn(' k');">
<input id="letters" type="button" name="l" value="l" onClick="turn(' l');">
<input id="letters" type="button" name="m" value="m" onClick="turn(' m');">
<input id="letters" type="button" name="n" value="n" onClick="turn(' n');">
<input id="letters" type="button" name="o" value="o" onClick="turn(' o');">
<input id="letters" type="button" name="p" value="p" onClick="turn(' p');">
<input id="letters" type="button" name="q" value="q" onClick="turn(' q');">
<input id="letters" type="button" name="r" value="r" onClick="turn(' r');">
<input id="letters" type="button" name="s" value="s" onClick="turn(' s');">
<input id="letters" type="button" name="t" value="t" onClick="turn(' t');">
<input id="letters" type="button" name="u" value="u" onClick="turn(' u');">
<input id="letters" type="button" name="v" value="v" onClick="turn(' v');">
<input id="letters" type="button" name="w" value="w" onClick="turn(' w');">
<input id="letters" type="button" name="x" value="x" onClick="turn(' x');">
<input id="letters" type="button" name="y" value="y" onClick="turn(' y');">
<input id="letters" type="button" name="z" value="z" onClick="turn(' Z');"><br />
Number of Tries (6): <input id="lives" type="text" value="0" onfocus="lives. blur();" SIZE=2>
<input type="button" name="submit" value=" Start Over " onClick="gamePr ocess()">
<input type="button" name="end" value=" END " onClick="gameEn d()"><br />
</form>
<p> </p>
<H2>Direction s</H2>
Please guess a letter to see if you figure out the secret word.<br />
You will have 6 chances to guess the word, or guess a letter.<br />
If you guess incorrectly you will lose a chance and your clown will be one step closer to being hung!<br />
Good Luck!
</body>
</html>[/HTML]
I am trying to create a hangman game. I am in a basic javascripting class.
I am to only use very basic code as you can see. I am able to use any online resources to help me.
I have added alot of comments for what should be happening however is not happening.
I also have a teacher that teaches us one way but then asks us to do things he has not taught. I am trying my very best.
Any help is greatly appreciated!
[HTML]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Hangma n</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript" language="JavaS cript">
var NumberOfChances ;
var theWord = "";
var currentGuessed = "";
//Array of 50 secret words
var words = new Array();
words[0]="computer";
words[1]="electronic ";
words[2]="negative";
words[3]="positive";
words[4]="ambassador ";
words[5]="dictionary ";
words[6]="maintain";
words[7]="responsibl e";
words[8]="adventure" ;
words[9]="sunshine";
words[10]="friendship ";
words[11]="attention" ;
words[12]="surgery";
words[13]="genealogy" ;
words[14]="investment ";
words[15]="mathematic s";
words[16]="journey";
words[17]="interest";
words[18]="moment";
words[19]="military";
words[20]="developmen t";
words[21]="enjoyment" ;
words[22]="encouragement ";
words[23]="hygiene";
words[24]="enlistment ";
words[25]="hyphenatio n";
words[26]="orientatio n";
words[27]="references ";
words[28]="highlight" ;
words[29]="recipients ";
words[30]="envelopes" ;
words[31]="preview";
words[32]="translatio n";
words[33]="research";
words[34]="grammar";
words[35]="thumbnails ";
words[36]="document";
words[37]="position";
words[38]="window";
words[39]="conversation" ;
words[40]="recommendatio ns";
words[41]="experience ";
words[42]="reference" ;
words[43]="failure";
words[44]="dignity";
words[45]="faithfulness" ;
words[46]="recklessness" ;
words[47]="leftovers" ;
words[48]="remainder" ;
words[49]="difficulty ";
words[50]="boxes";
//hangman series of images
var image = new Array();
image[0] = '<img src="images/image0.jpg" align ="left" width="415" height="496">';
image[1] = '<img src="images/image1.jpg" align ="left" width="415" height="496">';
image[2] = '<img src="images/image2.jpg" align ="left" width="415" height="496">';
image[3] = '<img src="images/image3.jpg" align ="left" width="415" height="496">';
image[4] = '<img src="images/image4.jpg" align ="left" width="415" height="496">';
image[5] = '<img src="images/image5.jpg" align ="left" width="415" height="496">';
image[6] = '<img src="images/image6.jpg" align ="left" width="415" height="496">';
document.getEle mentById('Image ').innerHTML = '<img src = "Image' + count + '.jpg" />';
NumberOfChances = image.length;
//swap the images for the hangman, start with image[0], then replace the image with each wrong guess, 6 chances
function swap(image)
{
var content=documen t.getElementByI d("imgID"+image ).src;
}
// an array to store the letters guessed if i can not figure out how to disable onclick of letters in form,
//want to highlight them red to so the player sees that they already choose that letter
var usedLetters = new Array();
for (i=0; i<letterguessed ; i++)
// creating the random pick of the secret word out of 50 choices
function secretWord()
{
theWord = words[Math.floor(Math .random()*51)];
for (i=0; i<theWord.lengt h; i++)
{
currentGuessed = currentGuessed + "*";
}
}
//the process that starts the game and resets it when the player chooses to play again
function gameProcess()
{
currentGuessed ="";
secretWord();
NumberOfChances =0;
startImage = image[0];
while (NumberOfChance s<7)
{
// not here move somewhere
onload= "gameProces s()" //
turn();
}
}
//this is what happens when the player takes a turn
function turn(letterGues sed)
{
var correctGuess = False;
for (i=0; i<theWord.lengt h; i++)
{
if (theWord[i] == letterGuessed)
{
currentGuessed[i] = letterGuessed;
correctGuess=Tr ue;
}
}
if (!correctGuess)
{
NumberOfChances ++;
if (NumberOfChance s==7)
{
alert("You Lost!")
}
if(correctGuess != 0)
{
takeChance();
}
win();
}
}
function win()
{
var winCount = 0;
for(var i = 0;i<word.length ;i++)
{
if(wordDisplay[i] == "*")
{
winCount++;
}
}
if(winCount == 0)
{
document.write( "yay, you win!");
}
}
</script>
</head>
<body>
<!--need to use Div tags -->
<H1> Hang De Clown</H1>
<!--hangman pic displaying first image, need to swap images with each wrong guess -->
<div id=Image><img src='images/image0.jpg' align ="left" width="415" height="496"></div>
<div id="wordDisplay "></div>
<!-- form for guessing letter,display secret word, display number of guesses left, restart, end game -->
<form name="userGuess Form">
This is the Secret Word<br /><input id="secretWord " type=text value="currentG uessed" />
<br />
<input id="letters" type="button" name="a" value="a" onClick="turn(' a');"><!-- as player guess wrong letter change to red and make unusable so player can not choose the letter again-->
<input id="letters" type="button" name="b" value="b" onClick="turn(' b');">
<input id="letters" type="button" name="c" value="c" onClick="turn(' c');">
<input id="letters" type="button" name="d" value="d" onClick="turn(' d');">
<input id="letters" type="button" name="e" value="e" onClick="turn(' e');">
<input id="letters" type="button" name="f" value="f" onClick="turn(' f');">
<input id="letters" type="button" name="g" value="g" onClick="turn(' g');">
<input id="letters" type="button" name="h" value="h" onClick="turn(' h');">
<input id="letters" type="button" name="i" value="i" onClick="turn(' i');">
<input id="letters" type="button" name="j" value="j" onClick="turn(' j');">
<input id="letters" type="button" name="k" value="k" onClick="turn(' k');">
<input id="letters" type="button" name="l" value="l" onClick="turn(' l');">
<input id="letters" type="button" name="m" value="m" onClick="turn(' m');">
<input id="letters" type="button" name="n" value="n" onClick="turn(' n');">
<input id="letters" type="button" name="o" value="o" onClick="turn(' o');">
<input id="letters" type="button" name="p" value="p" onClick="turn(' p');">
<input id="letters" type="button" name="q" value="q" onClick="turn(' q');">
<input id="letters" type="button" name="r" value="r" onClick="turn(' r');">
<input id="letters" type="button" name="s" value="s" onClick="turn(' s');">
<input id="letters" type="button" name="t" value="t" onClick="turn(' t');">
<input id="letters" type="button" name="u" value="u" onClick="turn(' u');">
<input id="letters" type="button" name="v" value="v" onClick="turn(' v');">
<input id="letters" type="button" name="w" value="w" onClick="turn(' w');">
<input id="letters" type="button" name="x" value="x" onClick="turn(' x');">
<input id="letters" type="button" name="y" value="y" onClick="turn(' y');">
<input id="letters" type="button" name="z" value="z" onClick="turn(' Z');"><br />
Number of Tries (6): <input id="lives" type="text" value="0" onfocus="lives. blur();" SIZE=2>
<input type="button" name="submit" value=" Start Over " onClick="gamePr ocess()">
<input type="button" name="end" value=" END " onClick="gameEn d()"><br />
</form>
<p> </p>
<H2>Direction s</H2>
Please guess a letter to see if you figure out the secret word.<br />
You will have 6 chances to guess the word, or guess a letter.<br />
If you guess incorrectly you will lose a chance and your clown will be one step closer to being hung!<br />
Good Luck!
</body>
</html>[/HTML]
Comment