JMRKER's Profile User Rating: -----

Reputation: 125 Stalwart
Group:
Active Members
Active Posts:
818 (0.41 per day)
Joined:
25-October 08
Profile Views:
8,688
Last Active:
User is online 52 minutes ago
Currently:
Viewing Topic: Hangman

Previous Fields

Country:
US
OS Preference:
Who Cares
Favorite Browser:
FireFox
Favorite Processor:
Who Cares
Favorite Gaming Platform:
Who Cares
Your Car:
Who Cares
Dream Kudos:
0

Latest Visitors

Icon   JMRKER has not set their status

Posts I've Made

  1. In Topic: Hangman

    Posted 18 Apr 2014

    Referencing "type=cell" only works if you have a <table> defined and displayed.
    I don't see any table definition in your program. Not it the original nor in your post #6.

    If you really need help, post ALL relevant code including HTML, CSS and JS referenced.
  2. In Topic: Hangman

    Posted 18 Apr 2014

    Not the best way to collect words for the game, but as a demo...
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8" />
    
    <title> Untitled </title>
    
    </head>
    <body>
    <h2>Create hangman words</h2>
    <button onclick="addWords()">Add Words</button>
    <button onclick="showWords()">Show Words</button>
    
    <script type="text/javascript">
    var hangman = [];
    
    function addWords() {
      var resp = prompt('Add new hangman word','');
      hangman.push(resp);
    }
    function showWords() {
      alert(hangman.join('\n'));
    }
    </script>
    
    </body>
    </html>
    
    


    NOTE: There is no option to correct mis-spelled words or garbage entries with this approach.
  3. In Topic: Hangman

    Posted 17 Apr 2014

    Caution. I tried to follow your logic but there were too many error to talk about.
    So, look at the major modifications to your code. I tried to keep the outline, just not the logic.

    <!doctype html>
    <html>
    <meta charset="UTF-8">
    <head>
    <style type="text/css">
     .btnLetter { width:30px; }
    </style>
    
    <script type="text/javascript">
    var wordArr = [], guesses = [], guessesRemaining = 0;
    var HangmanWords = ['Hello','Goodbye','Aloha','Hola','Adios'];
    var word = HangmanWords[0];                                                // for testing purposes only
    // var word = HangmanWords[Math.floor(Math.random()*HangmanWords.length];  // for random selections
    
    var init = function() { //in this function the word is split into letters and made an object to categorize letters
      guesses = [];
      wordArr = word.toUpperCase().split("");
      draw(); //draw the first time _ _ _ _ _ _ _
    }
    
    function draw() {  // $('debug').innerHTML = wordArr+'<br>'+guesses;  // for testing purposes only
      var count = 0;   // This variable holds the number of mistakes
      var output = ''; // reset the temporary output string
      for (var i=0; i<wordArr.length; i++) { // loop through all the guess letters
        var fnd = -1;
        for (var j=0; j<guesses.length; j++) {
          if (wordArr[i] == guesses[j]) { fnd = i; }
        }
        if (fnd != -1) { output += wordArr[i]+ ' '; } else { output += '_ ';  count++; }
      }
      output += ' : ' + count + ' letters to find.'; // optional: add the number of mistakes to the output
      guessesRemaining = count;
      $('output').innerHTML = output; // print the output in the output container
    }
    
    function Test(letter) { //This function checks if the chosen letter is valid
      if (guesses.indexOf(letter) == -1) { guesses.push(letter); }
      draw(); // draw the line
      winning = word.length - guesses.length;
      if (guessesRemaining == 0) { alert('You won!'); }  // if the user won
      else { if ( (guesses.length - wordArr.length) >= 5) { alert('You lost (:'); } }  // lose if 5 guesses too many for length of hangman word
    }
    
    function showLetterPicks() {
      var str = '', c = '', lid = '';
      for (var i=0; i<26; i++) {
        c = String.fromCharCode(i+65);  lid = c+'letter';
        str += '<input type="button" id="'+lid+'" class="btnLetter"';
        str += ' value="'+c+'" onclick="Test(this.value); $(this.id).style.backgroundColor=\'red\'" />';
        if ( (i % 13) == 12) { str += '<br>'; }
      } $('letterInput').innerHTML = str;
    }
    
    var $ = function(id) { return document.getElementById(id); } //misc. function for making selecting elements easier.
    </script>
    </head>
    
    <body onload="init();showLetterPicks()">
    <div id="output"></div><p>
    <div id="letterInput"></div>
    <p><div id="debug"></div>
    </body>
    
    
  4. In Topic: Modification to Yatzee game from earlier post.

    Posted 29 Mar 2014

    Ahh ... stupid mistake!

    Thanks for the eyeballing.

    :)
  5. In Topic: Dice Game

    Posted 28 Mar 2014

    I looked at this thread and decided I should be able to modify it
    to a "Yatzee" style game with a few changes. For the most part
    I was able to do this and although it is not finished yet, I have
    run into a problem I'm not sure I understand why it happens.

    Based on the post #4, I started a new thread
    at: http://www.dreaminco...m-earlier-post/
    so as to not hijack original posters (OP) thread.

    If you have any ideas, please look at link above.

My Information

Member Title:
D.I.C Addict
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:
Location:
Florida
Programming Languages:
javascript, perl, java, forth, basic, fortran, assembly (several)

Contact Information

E-mail:
Private
Website URL:
Website URL  http://

Comments

JMRKER has no profile comments yet. Why not say hello?