HTML and CSS Reference
In-Depth Information
The “Guess The Letter” Game Variables
Hereisarundownofthevariableswewilluseinthegame.Theyarealldefinedandinitialized
in canvasApp() , so they have scope to the encapsulated functions that we define locally:
guesses
Thisvariableholdsthenumberoftimestheplayerhaspressedaletter.Thelowerthenum-
ber, 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
letters
Thisarrayholdsoneofeachletterofthealphabet.Wewillusethisarraytobothrandomly
choose asecret letter forthe game andtofigure outthe relative position ofthe letter inthe
alphabet.
today
today
Thisvariable holdsthecurrentdate.Itisdisplayed onthescreenbuthasnootherpurpose.
letterToGuess
This variable holds the current game's secret letter that needs to be guessed.
higherOrLower
higherOrLower
Thisvariableholdsthetext“Higher”or“Lower,”dependingonwherethelastguessedlet-
terisinrelationtothesecretletter.Ifthesecretletteriscloserto“a,”wegivethe“Lower”
instruction. If the letter is closer to “z,” we give the “Higher” instruction.
lettersGuessed
This array holds the current set of letters that 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:
Search WWH ::




Custom Search