Javascript 带if-else的未终止字符串常量

Javascript 带if-else的未终止字符串常量,javascript,jquery,Javascript,Jquery,我正在编写一个测验,需要它根据分数显示特定的答案 当我刚刚显示分数时,它就起作用了,但是现在我已经添加了if-else,它已经停止工作了,我得到了一个未终止的字符串常量 $total_score = $first_question + $second_question + $third_question + $fourth_question + $fifth_question + $sixth_question + $seventh_question + $eighth_question + $

我正在编写一个测验,需要它根据分数显示特定的答案

当我刚刚显示分数时,它就起作用了,但是现在我已经添加了if-else,它已经停止工作了,我得到了一个未终止的字符串常量

$total_score = $first_question + $second_question + $third_question + $fourth_question + $fifth_question + $sixth_question + $seventh_question + $eighth_question + $ninth_question + $tenth_question + $eleventh_question + $twelfth_question + $thirteenth_question + $fourteenth_question + $fifthteenth_question + $sixteenth_question ;
});

$("#btn").click(function() {
   $('#reveal').html("<h3><strong>Total score</strong> " + $total_score +"</h3>"); 

if ($total_score >= 13) {
$('#answer').html("<h3><strong>13-16: Answer</strong></h3>"); 

} else if ($total_score >=9 && $total_score <= 12) {
$('#answer').html("<h3><strong>9-12: answer</strong></h3>"); 

} else if ($total_score >=5 && $total_score <= 8) {
$('#answer').html("<h3><strong>5-8: answer</strong></h3>"); 


 } else {
 $('#answer').html("<h3><strong> everything else</strong></h3>"); 
 }

});
$总分=$第一题+$第二题+$第三题+$第四题+$第五题+$第六题+$第七题+$第八题+$第九题+$第十题+$第十一题+$第十二题+$第十三题+$第十四题+$第十五题+$第十六题;
});
$(“#btn”)。单击(函数(){
$(“#显示”).html(“总分”“+$Total_分数+”);
如果($total_score>=13){
$(“#答案”).html(13-16:answer”;

}否则,如果($total_score>=9&&$total_score=5&&$total_scoreJavascript将行尾大致视为分号(;),那么您不能像脚本中那样使用多行字符串。删除它们,就可以了。

除了@Spork指出的换行符外,还需要删除多余的“}”)在计算$total_分数后:

    $total_score = $first_question + $second_question + $third_question + $fourth_question + $fifth_question + $sixth_question + $seventh_question + $eighth_question + $ninth_question + $tenth_question + $eleventh_question + $twelfth_question + $thirteenth_question + $fourteenth_question + $fifthteenth_question + $sixteenth_question ;
    /* must remove the following:
    });
    */
    $("#btn").click(function() {
        $('#reveal').html("<h3><strong>Total score</strong> " + $total_score +"</h3>"); 

        if ($total_score >= 13) {
            $('#answer').html("<h3><strong>13-16: Answer </strong></h3>"); 

        } else if ($total_score >=9 && $total_score <= 12) {
            $('#answer').html("<h3><strong>9-12: answer </strong></h3>"); 

        } else if ($total_score >=5 && $total_score <= 8) {
            $('#answer').html("<h3><strong>5-8: answer </strong></h3>"); 
        } else {
            $('#answer').html("<h3><strong> everything else</strong></h3>"); 
        }

    });
$总分=$第一题+$第二题+$第三题+$第四题+$第五题+$第六题+$第七题+$第八题+$第九题+$第十题+$第十一题+$第十二题+$第十三题+$第十四题+$第十五题+$第十六题;
/*必须删除以下内容:
});
*/
$(“#btn”)。单击(函数(){
$(“#显示”).html(“总分”“+$Total_分数+”);
如果($total_score>=13){
$(“#答案”).html(13-16:answer”;

}否则如果($total_score>=9&&$total_score=5&&$total_score是否有新行开始
您是否考虑过在循环中执行
$total_score=
部分?我更新了代码以将行移动到正确的位置,但第二行仍然会出错,否则如果我无法开始工作,您还有一个额外的
})
在你的粘贴中…除此之外,你还需要扩展你的示例。所有这些都有助于解决问题。谢谢。你可以,但我不建议。我想你在一行末尾加上反斜杠,这样你就可以在下一行继续使用字符串了。也谢谢你的帮助@sporkI find使用JavaScript语法编辑器/调试器(Eclipse,VS 2012 Web Developer Express-两者都是免费的)确实有助于查明此类错误。