How do I create a function for my hangman game in code.org?
I need to make a "Hint" button, so that when I press the button, the hint that goes to the word you're going to guess, gives you a clue.
Example
My word is abandon
and the clue would say following when I click on the "Hint" button:
To cease to support or look after (someone); desert
I already made the variables for the guess words in the hangman game like:
var words= ["abandon", "above", "about"];
var word = "";
I made a little mock up of what your describing. Since Code.org is have design and half code, note my design. Your can interact with my design sample hangman program.
I made a corresponding list
hints
. I then select a random number and store inindex
. This tells me which spot inwords
andhints
to use.I then implement my three buttons. The first,
hintBtn
, sets the text of the label, and unhides it (it was hidden as part of DesignMode).The second button,
newWordBtn
, picks a differentindex
to use as the answer. It also makes the hint hidden again (we change the text of the hint label when the user clickshintBtn
).I've left the
guessBtn
for you to fully implement.Hope this helps.