在刽子手游戏中显示提示模式js UPDATE

时间:2018-04-14 10:21:55

标签: javascript

现在在实施提示模式后,猜测部分不起作用,这意味着我无法猜出一封信。这意味着生命不会减少,任何人都无法赢或输。提示模式完美无缺。

selectedIndex

据我所知,变量仍然相同,所以我不明白为什么会出现错误?

3 个答案:

答案 0 :(得分:1)

您声明了一个包含数组的数组:

   hints = [
        ["Stoke Greeting","Saying Something is Easy", "Very Clumsy","delaying something for a minute", "When you are jealous of something","Something is frightening", "Earn Money", "Rough Exterior however has some potential", "When something rarely happens", "When you have succeeded/ getting yourself known by a company","accepting something , when you do not want to"]  
         ];

将其更改为简单数组:

hints = ["Stoke Greeting","Saying Something is Easy", "Very Clumsy","delaying something for a minute", "When you are jealous of something","Something is frightening", "Earn Money", "Rough Exterior however has some potential", "When something rarely happens", "When you have succeeded/ getting yourself known by a company","accepting something , when you do not want to"];

答案 1 :(得分:0)

除了数组中的数组问题,你还需要存储索引本身并使用它而不是单词。

你也有拼写错误:hint.onclick应为getHint.onclick

var words = ["ayeupmeducks", "pieceofcake", "bullinachinashop", "hangfire","greeneyedmonster",       "hairraising","bringhomethebacon","adiamondintherough","onceinabluemoon","afootinthedoor","bitethebullet"];

var idx = Math.floor(Math.random() * words.length);
var currentWord = words[idx];

var getHint = document.getElementById("hint");
var showClue = document.getElementById("clue");

getHint.onclick = function() {
    var hints = ["Stoke Greeting","Saying Something is Easy", "Very Clumsy","delaying something for a minute", "When you are jealous of something","Something is frightening", "Earn Money", "Rough Exterior however has some potential", "When something rarely happens", "When you have succeeded/ getting yourself known by a company","accepting something , when you do not want to"];
    showClue.innerHTML = "Clue: - " +  hints [idx];
};
<button id="hint" name="hint" type="button">Hint</button>
<p id="clue">Clue: </p>

答案 2 :(得分:0)

对它进行排序 - 感谢您的帮助:) 我将当前单词从变量中更改为现在可以正常工作