为什么不显示下划线?

时间:2018-04-24 18:58:14

标签: javascript html arrays string

我正在尝试将我的刽子手游戏的下划线显示在HTML页面上,但它似乎没有起作用。当我运行HTML页面时,我看到的只是文本框。关于为什么会发生这种情况的任何想法?

CODE:

    //create array for words
    var listWords = ['cat', 'dog', 'mouse'];
    
    //displays the word in underscores
    var hiddenWord = [];
    
    //choose word randomly
    //Math.random returns integer between 0 (inclusive) and 1 (exclusive)
    //multiply Math.random with the length of the listWords array
    //Math.floor rounds down to nearest integer
    //note that array indexes start counting from 0, hence why we need to make sure the listWords index never reaches the actual length of the array
    var chosenWord = listWords[Math.floor(Math.random() * listWords.length)];
    
    //number of tries the user gets before game over
    var lives = 5;
    
    var s;
    
    function setup() {
    	for (i = 0; i < chosenWord.length; i++) {
    		hiddenWord[i] = '_';
    	}
    	s = hiddenWord.join(' ');
    	return s;
    }
    
    function main() {
    	var underscores = document.getElementById('hiddenWord');
    	underscores.innerHTML = setup();
    }
<!--adding a title that will appear on the webpage-->
<h1>Hangman</h1>

<!--create a text box-->
  <input id='letter' type='text' maxlength="1" minlength="1" placeholder="Guess a letter" />

<div id='hiddenWord'></div>

<!--add instructions for the player-->
<h2>Instructions</h2>

0 个答案:

没有答案