I am currently making a simple hang-man game using a browser.
When the user clicks on a button, it calls a function pickWord()
:
<button onclick="pickWord()" id="restart">Pick A Word</button>
The function then picks a random word from the dictionary, assigns it to a variable, and creates the spaces ( _ _ _ _) for the word to put in an html table.
function pickWord()
{
var word = dictionary[Math.floor(Math.random()*dictionary.length)];
wordSpaces = "_" * word.length;
document.getElementById('spaces').innerHTML = wordSpaces;
}
This is not working: The spaces are not displayed on the table.
I made a JSFiddle to help solve the problem.