1. Home
  2. Computing & Technology
  3. JavaScript

Hangman Script Tutorial

page eight

clr gif

 

<< Previous Page

document.write('<div class="hangb">');
if (win == 0) availLetter();
else if (win == 4)
document.write('<div class="hangt">YOU WIN<br \/><a
continued from previous line href="'+page+'">Try Again<\/a><\/div>');
else document.write('<div class="hangt">YOU LOSE<br \/><a
continued from previous line href="'+page+'">Try Again<\/a><\/div>');
document.write('<div align="center">&nbsp;<br \/><img
continued from previous line src="'+img+'hang'+wx+'.gif" width="100" height="100"
continued from previous line alt="hangman image '+wx+'" \/><br \/>&nbsp;<\/div>');
displayAnswer();
document.write('<\/div>');

This final piece of code is what runs all of the other functions. If the game hasn't finished it calls the availLetter function to display the letters that are still available for the next guess. If the game is over it displays whether the game was won or lost followed by a link allowing the person to run the game again.

Under this is displayed an image indicating the current status of the game. The game uses eleven images to represent the gradual addition of body parts to the hangman as up to ten wrong guesses are made. Finally below that the displayAnswer function is called to display the answer field with dashes showing where letters remain to be guessed.

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.