1. Home
  2. Computing & Technology
  3. JavaScript

Hangman Script

2. Alternative Body Script

clr gif

If you want a variation on the hangman game that doesn't look like a hangman game then perhaps this version that replaces the hangman images with a short statement that is gradually highlighted as wrong guesses are made may suit you better.

This version works as a direct substitute for the version of the game that uses images making it easy to swap from one version to the other at any time just by replacing the one body script with the other. The same head script and stylesheets are used by both versions.

To get the alternative body script that doesn't need images you simply start by highlighting and copying the below Javascript and then save it as a file called hangb.js. There is a button below the form to make highlighting the code easier.

If you wish you may change the content of the word variable at the top of the script to be whatever 10 letters (or other characters) that you want to use with your version of the game.

If you are adding the script to the page for the first time rather than just replacing the images version you need to link this code into the body of your page where you want the script to appear using the following code:

<script src="hangb.js" type="text/javascript">
</script><noscript><div align="center"><b>The Hangman
game requires Javascript</b><br />You either have
Javascript disabled<br />or the browser you are using does
not<br />support Javascript. Please use a Javascript
<br />enabled browser to access this game.</div></noscript>

The next step if you are setting up a new game is to set up a selection of answers that will go into a script in the head of the page.

To see how scripts created with this generator actually work for the no images version take a look at my Javascript Objects Hangman.

Explore JavaScript
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. JavaScript

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

All rights reserved.