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/


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -