javascript - Getting Error, "Cannot set property [0] of undefined" -
trying practice writing hangman program, , @ part function loop on word guessed, , set dashes '_' array based on length of word guessed. working until added function "putdashes()" take dashes in array , add them html on screen user guess. getting error, "cannot set property [0] of undefined". please assist
function wordselect(selectdashes){ // define wordbank object wordbank =["westworld", "startrek", "legion", "gameofthrones", "archer", "simpsons", "bobsburgers", "janethevirgin", "seinfeld", "rachelmaddow"]; // pick random word wordbank currentword = wordbank[(math.floor(math.random()*wordbank.length+1))]; console.log(currentword); selectedword=[]; selectedword=currentword.split(""); for(var i=0; i<currentword.length; i++) { selectdashes[i]="_"; // selectdashes.push("_"); } console.log(selectedword); console.log(selectdashes); lettersremaining=selectedword.length; document.getelementbyid("lettersnword").innerhtml=lettersremaining; guessesremaining=5; document.getelementbyid("guesscounter").innerhtml=guessesremaining; putdashes(); };
Comments
Post a Comment