试图将变量“randomWord”打印到 console.log,但 chrome 说它没有定义。它看起来像是对我定义的。为什么它不会打印到 console.log?
function strt(){
//get random word from words[] array
var randomWord = words[Math.floor(Math.random()* words.length)];
var wordLength = randomWord.length;
//create a blank boxes or div elements for holding each letter of
// selected random word
for(i = 0 ; i< wordLength; i++){
var divTag = document.createElement("div");
divTag.id = "div" + i;
divTag.className = 'wordy';
//divTag.innerHTML = randomWord[i];
hangManDiv.appendChild(divTag);
};// end for loop
//disable start button
document.getElementsByName("startB")[0].disabled = true;
return randomWord;
}//end strt()
console.log(randomWord);