HTML and CSS Reference
In-Depth Information
guesses
This variable holds the number of times the player has pressed a letter. The lower
the number, the better he has done in the game.
message
The content of this variable is displayed to give the user instructions on how to play.
letters
This array holds one of each letter of the alphabet. We will use this array to both
randomly choose a secret letter for the game, and to figure out the relative position
of the letter in the alphabet.
today
This variable holds the current date. It is displayed on the screen but has no other
purpose.
letterToGuess
This variable holds the current game's secret letter that needs to be guessed.
higherOrLower
This variable holds the text “Higher” or “Lower” depending on where the last
guessed letter is in relation to the secret letter. If the secret letter is closer to “a,”
we give the “Lower” instruction. If the letter is closer to “z,” we give the “Higher”
instruction.
lettersGuessed
This array holds the current set of letters the player has guessed already. We will
print this list on the screen to help the player remember what letters he has already
chosen.
gameOver
This variable is set to false until the player wins. We will use this to know when
to put the “You Win” message on the screen, and to keep the player from guessing
after he has won.
Here is the code:
var guesses = 0;
var message = "Guess The Letter From a (lower) to z (higher)";
var letters = [
"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 today = new Date();
var letterToGuess = "";
var higherOrLower = "";
var lettersGuessed;
var gameOver = false;
Search WWH ::




Custom Search