Javascript 代码不是';t执行,可能有语法问题,或者我可能完全错了

Javascript 代码不是';t执行,可能有语法问题,或者我可能完全错了,javascript,jquery,Javascript,Jquery,所以我有一个简单的项目-创建一个刽子手游戏。我有一个令人难以置信的基本游戏《刽子手》,只有一个单词,没有数组被使用、编码和工作。在添加加法猜测和随机单词的数组后,它将不再工作 据我所知,它不再选择一个单词(取代字母的破折号现在只显示一个破折号,以前没有数组,我有一个预设单词,它为每个字母显示破折号),因此所有猜测都是错误的。第二,尽管所有这些猜测都是错误的,但没有一个被计算在内 JSfiddle- HTML- <body> <form id="form" name="for

所以我有一个简单的项目-创建一个刽子手游戏。我有一个令人难以置信的基本游戏《刽子手》,只有一个单词,没有数组被使用、编码和工作。在添加加法猜测和随机单词的数组后,它将不再工作

据我所知,它不再选择一个单词(取代字母的破折号现在只显示一个破折号,以前没有数组,我有一个预设单词,它为每个字母显示破折号),因此所有猜测都是错误的。第二,尽管所有这些猜测都是错误的,但没有一个被计算在内

JSfiddle-

HTML-

<body>


<form id="form" name="form" method="post" action="">
<input type="button" id="but" value="Start"/>
<div id="hangman-jquery">
    <div id="word"></div>
    <div id="alpha"></div>
</div>
</form>

<div id="win">
</div>

<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="hangman.js"></script>
</body>

jquery-

function hangman(word) {
    var trys = 0
    var alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $.each(alpha.split(''), function(i, val) {
        $('#alpha').append($('<span class="guess">' + val + '</span>'));
    });
    $.each(word.split(''), function(i, val) {
        $('#word').append($('<span class="letter" letter="' + val + '">-</span>'));
    });
    $('.guess').click(function() {
        var count = $('#word [letter=' + $(this).text() + ']').each(function() {
            $(this).text($(this).attr('letter'));
        }).length;
        $(this).removeClass('guess').css('color', (count > 0 ? 'green' : 'red')).unbind('click');

        if (guess > 0) {
        $('#win').text("Correct Guess");
        } else if (guess < 0) {
        $(this).html(++trys);
        $('#win').text("You have tried to guess the word and failed " + trys + " times");
        }
        if (trys == 6) {
        alert("You have guessed six times, you lose");
        trys = 0;
        $("#win").text("");
        }
    });
}

$(document).ready(function() {
    $('#but').click(function() {
        var options = new Array("Dog", "Cat", "Bat", "Horse", "Tiger", "Lion", "Bear", "Liger", "Doom", "Spider", "Trees", "Laptop");
        var random = 1 + Math.floor(Math.random() * 12);
        hangman('options'[random]);
    });
});

/*Createa web page with the game Hangman, in which the user guesses letters in a hidden word. 
Create an array with at least a dozen words and pick one at random each time the game is started. 
Display a dash for each missing letter. Allow the user to guess letters continuously 
(up to 6 guesses) until all the letters in the word are correctly guessed. 
As the user enters each guess, display the word again, filling in the guess if it was correct. 
For example, if the hidden word is “ computer”, first display --------. 
After the user guesses “ p”, the display becomes ---p----. Make sure that when a user makes a 
correct guess, all the matching letters are filled in. For example, if the word is “ banana”, then
when the user guesses “ a”, all three “ a” characters are filled in. (25 points)
*/
功能刽子手(word){
var trys=0
var alpha='abcdefghijklmnopqrstuvxyz';
$.each(alpha.split(“”),函数(i,val){
$('#alpha')。追加($(''+val+'');
});
$.each(单词分割(“”),函数(i,val){
$('#word')。追加($('-');
});
$('.guess')。单击(函数(){
变量计数=$('#单词[字母='+$(this.text()+'])。每个(函数(){
$(this.text($(this.attr('letter'));
}).长度;
$(this).removeClass('guess').css('color',(计数>0?'green':'red')).unbind('click');
如果(猜测>0){
$('#win')。文本(“正确猜测”);
}else if(猜测<0){
$(this.html(++trys);
$(“#win”).text(“您试图猜单词但失败了”+trys+“次”);
}
如果(trys==6){
警惕(“你猜了六次,你输了”);
trys=0;
$(“#赢”).text(“”);
}
});
}
$(文档).ready(函数(){
$('#but')。单击(函数(){
var选项=新阵列(“狗”、“猫”、“蝙蝠”、“马”、“老虎”、“狮子”、“熊”、“狮虎”、“厄运”、“蜘蛛”、“树”、“笔记本”);
var random=1+Math.floor(Math.random()*12);
刽子手(“选项”[随机]);
});
});
/*使用游戏Hangman创建一个网页,用户在其中猜测隐藏单词中的字母。
创建一个至少包含十几个单词的数组,并在每次游戏开始时随机选取一个单词。
为每个缺少的字母显示破折号。允许用户连续猜测字母
(最多6次猜测)直到单词中的所有字母都猜对为止。
当用户输入每个猜测时,再次显示单词,如果猜测正确,则填写猜测。
例如,如果隐藏的单词是“computer”,则首先显示--------。
用户猜到“p”后,显示变成--p---。确保当用户进行
猜对了,所有匹配的字母都填好了。例如,如果单词是“香蕉”,那么
当用户猜到“a”时,所有三个“a”字符都被填写。(25分)
*/
最后我把我的指示写了进去,以防有人想看一遍。否则,就我所知,我不会犯任何错误(我还不太擅长理解firebug),只是没有做到我所希望的

提前谢谢你。你一如既往的帮助是无价的

you wrote hangman('options'[random]);
选项是一个变量,所以它不应该在引号之间。 它现在做的是从字符串“option”中提取一个随机字符

此外,guess在hangman函数中没有定义