html - Javascript: Hang-Man Function Not Working -
i making simple hang-man game using browser.
when user clicks on button, calls function pickword()
:
<button onclick="pickword()" id="restart">pick word</button>
the function picks random word dictionary, assigns variable, , creates spaces ( _ _ _ _) word put in html table.
function pickword() { var word = dictionary[math.floor(math.random()*dictionary.length)]; wordspaces = "_" * word.length; document.getelementbyid('spaces').innerhtml = wordspaces; }
this not working: spaces not displayed on table.
i made jsfiddle solve problem.
you can't apply multiplication string , number, need use loop build wordspaces
string.
there comma missing after first line in dictionary
array.
in jsfiddle, javascript code wrapped inside onload
function, didn't have pickword in global scope.
updated: https://jsfiddle.net/24eqxlpn/1/