Hangman Game - Guess a letter


#1


Hi everyone!

I decided to start with the hangman and I'm trying to find the best way to setup the alphabet and save the value of the guessed letter.

This is what I have now, but I don't know how to save the clicked letter in a variable. Should I program it differently?


var abc = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"];
var HTMLletterStart = '<div class="letter-entry"></div>';
var HTMLletter = '<div class="ABCletter">%data%</div>';

for (var i = 0; i < abc.length; i++){
    $('.ABCletters').append(HTMLletterStart);
    var formattedLetter = HTMLletter.replace("%data%", abc[i]);
    $(".letter-entry:last").append(formattedLetter);
}


#2

Not sure what you mean by "saving the value of the guessed letter" or "save the clicked letter"
If you mean a representation of what the user sees (initially all underscores), wouldn't an array support all the operations that you need?


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.