//First, we create an array of 'pictures', showing each state of the hangman picture=new Array("--------\n| |\n|\n|\n|\n|\n=====", "--------\n| O\n|\n|\n|\n|\n=====", "--------\n| O\n| |\n|\n|\n|\n=====", "--------\n| O\n| /|\n|\n|\n|\n=====", "--------\n| O\n| /|\\\n|\n|\n|\n=====", "--------\n| O\n| /|\\\n| |\n|\n|\n=====", "--------\n| O\n| /|\\\n| |\n| /\n|\n=====", "--------\n| O\n| /|\\\n| |\n| / \\\n|\n====="); //Next, we create an array of words for the computer to choose from vocabulary=new Array("Macquarie","JavaScript","Education","Navigator","blackboard"); //this function initialises all the variables, and chooses a word from the list function restart(){ numguesses=0; maxguesses=picture.length-1;//if there are 7 pictures, the last one must show the complete hangman, so the user must lose the game at that point guessed=" "; len=vocabulary.length;//determine number of words in list theWord=vocabulary[Math.round(len*Math.random())].toUpperCase();//pick a word at random, convert it to uppercase displayPicture();//calls the function to draw the gallows(at this point empty) displayWord();//displays the current state of the word(at this point all blanks) displayGuessed();//lists all the letters you have guessed so far(at this point none) } function displayPicture(){ hangForm.drawing.value=picture[numguesses];//draw the appropriate picture for the number of incorrect guesses made } function displayGuessed(){ hangForm.guessed.value=guessed; } function displayWord(){ output=""; for(i=0;i=maxguesses){ //if user runs out of guesses alert('Sorry, you lose. The word was ' +theWord); //put them out of their misery and tell them what the word was restart(); //then start over with a new word } if(winner()){ //if all letters in word have been guessed alert('You Win!'); //congratulate user restart(); //then start again with a new word } }