I am sure you remember playing hangman when you were younger where one person chose a word or phrase and the other person had to guess which letters that it contained. Every time they guessed wrong they were one step closer to being hanged. Enough wrong guesses before solving the word or phrase and they lost the game.
Copy and save the above content as hang.htm.
There are four lines in this code that allow our script to work. You can change anything else in the HTML to add whatever else you want in the page as long as the four lines remain intact.
- The reference to the hangq.js script will refer to our dynamically generated file containing the word the script uses as answers. You can change that name and create multiple files if you want multiple hangman games using different answers.
- The second script hangman.js is the static portion of the script that does all the actual work. You'll find the code for that below.
- The stylesheet that defines our page appearance is called hangman.css and is linked into the HTML using a link tag. Again the code is below.
- This div tag with id="hang" identifies the spot in the page where the hangman game is to appear.
The styles required for the hangman game are fairly simple and control how the game will look. You need to save the following in a file called hang.css.
Copy and save the above content as season.css.
You will not need to change anything in this code.