dcsimg
www.webdeveloper.com
Results 1 to 2 of 2

Thread: Help me add html code to the attached link

  1. #1
    Join Date
    Dec 2002
    Posts
    23

    Help me add html code to the attached link

    http://javascript.internet.com/games/hangman.html
    I like the script of this Hangman but would like to do it, not for Presidents, but for words. If they do or do not guess the word I would like to give them the meaning of the word (so the kids vocabulary can increase!)
    Can somebody help me by adding an html colde to it so that the meaning is displayed when the word is fully written (whether the word is guessed or it comes up as 'You lose' and the computer gives the word and the meaning.
    Thanks

  2. #2
    Join Date
    Nov 2002
    Posts
    631
    <BODY>

    <center>
    <table border=8 bgcolor=white width=60% cellspacing=0>
    <tr><td>
    <center>
    <h2>Hangman!</h2><br>
    <b><h3><font color=red>Topic:</font>
    Presidents of The United States</h3></b>
    <hr><br>

    <SCRIPT LANGUAGE="JavaScript">

    <!-- Original: Rick Glusick -->

    <!-- This script and many more are available free online at -->
    <!-- The JavaScript Source!! http://javascript.internet.com -->

    <!-- Begin
    function getCookie (name) {
    var dcookie = document.cookie;
    var cname = name + "=";
    var clen = dcookie.length;
    var cbegin = 0;
    while (cbegin < clen) {
    var vbegin = cbegin + cname.length;
    if (dcookie.substring(cbegin, vbegin) == cname) {
    var vend = dcookie.indexOf (";", vbegin);
    if (vend == -1) vend = clen;
    return unescape(dcookie.substring(vbegin, vend));
    }
    cbegin = dcookie.indexOf(" ", cbegin) + 1;
    if (cbegin == 0) break;
    }
    return null;
    }
    function setCookie (name, value, expires) {
    if (!expires) expires = new Date();
    document.cookie = name + "=" + escape (value) + "; expires=" + expires.toGMTString() + "; path=/";
    }
    function delCookie (name) {
    var expireNow = new Date();
    document.cookie = name + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT" + "; path=/";
    }
    var Alphabet = new initAlphaArray()
    var NumOfWords = 42;
    var SaveData = "";
    var ImageNum = "";
    var LettersSelected = "";
    var RandomWord = "";
    var DisplayWord = "";
    var position = 0;
    var word = new WordList();
    var expdate = new Date();
    var RandomNumber = (expdate.getSeconds())%NumOfWords;
    function initAlphaArray() {
    this.length = 26
    this[0] = "A"
    this[1] = "B"
    this[2] = "C"
    this[3] = "D"
    this[4] = "E"
    this[5] = "F"
    this[6] = "G"
    this[7] = "H"
    this[8] = "I"
    this[9] = "J"
    this[10] = "K"
    this[11] = "L"
    this[12] = "M"
    this[13] = "N"
    this[14] = "O"
    this[15] = "P"
    this[16] = "Q"
    this[17] = "R"
    this[18] = "S"
    this[19] = "T"
    this[20] = "U"
    this[21] = "V"
    this[22] = "W"
    this[23] = "X"
    this[24] = "Y"
    this[25] = "Z"
    }
    function WordList() {
    this.length = NumOfWords;
    this[0] = "GEORGE WASHINGTON";
    this[1] = "JOHN ADAMS";
    this[2] = "THOMAS JEFFERSON";
    this[3] = "JAMES MADISON";
    this[4] = "JAMES MONROE";
    this[5] = "JOHN QUINCY ADAMS";
    this[6] = "ANDREW JACKSON";
    this[7] = "MARTIN VAN BUREN";
    this[8] = "WILLIAM HENRY HARRISON";
    this[9] = "JOHN TYLER";
    this[10] = "JAMES POLK";
    this[11] = "ZACHARY TAYLOR";
    this[12] = "MILLARD FILLMORE";
    this[13] = "FRANKLIN PIERCE";
    this[14] = "JAMES BUCHANAN";
    this[15] = "ABRAHAM LINCOLN";
    this[16] = "ANDREW JOHNSON";
    this[17] = "ULYSSES GRANT";
    this[18] = "RUTHERFORD HAYES";
    this[19] = "JAMES GARFIELD";
    this[20] = "CHESTER ARTHUR";
    this[21] = "GROVER CLEVELAND";
    this[22] = "BENJAMIN HARRISON";
    this[23] = "GROVER CLEVELAND";
    this[24] = "WILLIAM MCKINLEY";
    this[25] = "THEODORE ROOSEVELT";
    this[26] = "WILLIAM HOWARD TAFT";
    this[27] = "WOODROW WILSON";
    this[28] = "WARREN HARDING";
    this[29] = "CALVIN COOLIDGE";
    this[30] = "HERBERT HOOVER";
    this[31] = "FRANKLIN ROOSEVELT";
    this[32] = "HARRY TRUMAN";
    this[33] = "DWIGHT EISENHOWER";
    this[34] = "JOHN KENNEDY";
    this[35] = "LYNDON JOHNSON";
    this[36] = "RICHARD NIXON";
    this[37] = "GERALD FORD";
    this[38] = "JIMMY CARTER";
    this[39] = "RONALD REAGAN";
    this[40] = "GEORGE BUSH";
    this[41] = "BILL CLINTON";
    }
    function availableLetters(i) {
    if (LettersSelected.charAt(i)==Alphabet[i])
    document.write('<TD ALIGN=CENTER VALIGN=CENTER WIDTH=20 HEIGHT=12>' +
    '<B><A HREF="javascript:LoadNextPage('+i+',\''+Alphabet[i]+
    '\')">'+Alphabet[i]+'</A></B></TD>');
    else
    document.write('<TD ALIGN=CENTER VALIGN=CENTER WIDTH=20 HEIGHT=12> </TD>');
    }
    function LoadNextPage(selected,letter) {
    var j=0;
    var HoldLettersSelected = LettersSelected;
    LettersSelected = "";
    if (selected == 0) {
    for (j=1; j<=25; j++) {
    LettersSelected += HoldLettersSelected.charAt(j);
    }
    LettersSelected = "^" + LettersSelected;
    }
    else if (selected == 25) {
    for (j=0; j<=24; j++) {
    LettersSelected += HoldLettersSelected.charAt(j);
    }
    LettersSelected += "^";
    }
    else {
    for (j=0; j<selected; j++)
    {
    LettersSelected += HoldLettersSelected.charAt(j);
    }
    LettersSelected += "^";
    for (j=selected+1; j<=25; j++) {
    LettersSelected += HoldLettersSelected.charAt(j);
    }
    }


    SaveData = ImageNum + LettersSelected + RandomWord + "*";
    setCookie("_HangMan", SaveData, expdate);
    history.go(0);
    }

    // Sets a cookie that will expire in 10 days

    expdate.setTime (expdate.getTime() + (1000*60*60*24*10));
    if(getCookie("_HangMan") == null)
    {
    ImageNum = "A";
    LettersSelected = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    RandomWord = word[RandomNumber];
    SaveData = ImageNum + LettersSelected + RandomWord + "*";
    setCookie("_HangMan", SaveData, expdate);
    }
    else {
    SaveData = getCookie("_HangMan");
    ImageNum = SaveData.charAt(0);
    for (position=1; position<=26; position++) {
    LettersSelected += SaveData.charAt(position);
    }
    for (position=27; position<SaveData.indexOf("*"); position++) {
    RandomWord += SaveData.charAt(position);
    }
    }
    DisplayWord = "";
    for (i=0; i<RandomWord.length; i++) {
    if (RandomWord.charAt(i) == ' ') {
    DisplayWord += " ";
    }
    else {
    MatchFound = false;
    for (j=0; j<=25; j++) {
    if ((LettersSelected.charAt(j) == "^") && (RandomWord.charAt(i) == Alphabet[j])) {
    DisplayWord += RandomWord.charAt(i);
    MatchFound = true;
    }
    }
    if (!MatchFound) DisplayWord += "-";
    }
    }
    if (ImageNum == "J") {
    document.write('<font color=red size=4>You Lost!<br>Answer: "' + RandomWord + '"</font>');
    }
    else if (RandomWord == DisplayWord) {
    document.write('<font color=red size=8>You Win!</font>');
    }
    else {
    document.write('<table>');
    document.write('<tr>');
    for (i=0; i<13; i++) availableLetters(i);
    document.write('</tr>');
    document.write('<tr>');
    for (i=13; i<26; i++) availableLetters(i);
    document.write('</tr>');
    document.write('</table>');
    }
    document.write('<br>');
    document.write('<br>');
    document.write('<font size=9><tt>');
    document.write(DisplayWord);
    document.write('</tt></font>');
    document.write('<form>');
    document.write('<input type="button" VALUE="New Game"'+
    'onClick="delCookie(\'_HangMan\');history.go(0);">');
    document.write('</form>');
    document.write('</center>');
    // End -->
    </SCRIPT>
    </td></tr>
    </table>
    </center>


    Up in this script it has a list of the Presidents from 0 to 41 (there are now 43). Just change those presidents names to words.

    About the meaning, that would take a while to make. I might work on that later.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles