JavaScript

  1. Home
  2. Computing & Technology
  3. JavaScript

Hangman Script

3. The Head Script

clr gif

The hangman script will randomly select an answer from a list of answers that you provide. Each answer can be a single word or phrase up to 19 characters long. Only letters and spaces can be used and any lowercase letters you enter will be converted to uppercase. You need to enter those answers one at a time into the form below. If you are using the original version of the body script which uses images then you will also need to enter the relative path to the location of the images that the script uses if you are not going to place them in the same folder as the hangman game web page. If you aare using the alternate no-image version then you can leave the image folder field blank.

Continue adding as many answers as you require. You can add up to 50 or 60 different words or phrases.

The script code for the hangman game will appear in the text box below with an additional statement being added for each answer you add. Don't worry if you make a mistake as you can always delete lines from the resulting code if you want to remove answers, just make a note of which entries they are as the answers are "encoded" to make it more difficult to cheat. If you decide you want to start over, simply refresh the current page.

Image Folder
Answer

Once you have finished entering your answers, copy the code from the above text box and save it as a file called hangh.js.

You now add this script to the head section of the page where the hangman game is to appear using the following code:

<script src="hangh.js"
type="text/javascript">
</script>

If you are creating more than one hangman game then you can use different names for the files where you save the answers as long as they end in .js and that you modify the code going into the head of the individual hangman pages to reference the appropriate files you have created. The code that you place into the body of each hangman page will be the same for each game.

The next step is to attach the stylesheet to the page.

To see how scripts created with this generator actually work take a look at this version of my Javascript Objects Hangman that uses images.

Explore JavaScript

About.com Special Features

JavaScript

  1. Home
  2. Computing & Technology
  3. JavaScript

©2009 About.com, a part of The New York Times Company.

All rights reserved.