简体   繁体   English

初学者 JS 标识符错误

[英]Beginner JS identifier error

I am getting an identifier error on the first 'else if'.我在第一个“else if”上收到标识符错误。 How come, and why dont i get another error for the second 'else if'?怎么会,为什么我没有收到第二个'else if'的另一个错误?

<p id="user"></p></p>
<p id="rock"></p>
<p id="paper"></p>
<p id="scisors"></p>
<p id="check"></p>
<script>
var userChoice = prompt("Do you choose rock, paper, or scissors?");
document.getElementById("user").innerHTML=(userChoice);
var computerChoice = Math.random();
if (computerChoice <=.3399){
document.getElementById("rock").innerHTML=("rock");
document.getElementById("rock").innerHTML+=(computerChoice);
};


else if (computerChoice >=.34<.67){
document.getElementById("paper").innerHTML=("paper");
document.getElementById("paper").innerHTML+=(computerChoice);
};

else if (computerChoice >=.67){
document.getElementById("scisors").innerHTML=("sciscors");
document.getElementById("scisors").innerHTML+=(computerChoice);
};
else if (computerChoice >=.34<.67){
document.getElementById("paper").innerHTML=("paper");
document.getElementById("paper").innerHTML+=(computerChoice);
};

Is likely whats intended... The problem is here:可能是什么意图......问题在这里:

else if (computerChoice >=.34<.67){

You cant just have two operators together... You can acomplish this in two ways:您不能同时拥有两个操作员...您可以通过两种方式完成此操作:

AND Operator: AND 运算符:

else if (computerChoice >=.34 && computerChoice<.67){
document.getElementById("paper").innerHTML=("paper");
document.getElementById("paper").innerHTML+=(computerChoice);
};

OR OPERATOR或运营商

else if (computerChoice >=.34 || computerChoice<.67){
    document.getElementById("paper").innerHTML=("paper");
    document.getElementById("paper").innerHTML+=(computerChoice);
    };

Semi-colon Error:分号错误:

if (computerChoice <=.3399){
document.getElementById("rock").innerHTML=("rock");
document.getElementById("rock").innerHTML+=(computerChoice);
};


else if (computerChoice >=.34<.67){
document.getElementById("paper").innerHTML=("paper");
document.getElementById("paper").innerHTML+=(computerChoice);
};

else if (computerChoice >=.67){
document.getElementById("scisors").innerHTML=("sciscors");
document.getElementById("scisors").innerHTML+=(computerChoice);
};

You cant have those semicolons before the else if statement as @squint said in the comments below.. Hope this helped正如@squint 在下面的评论中所说,你不能在 else if 语句之前使用那些分号。希望这有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2025 STACKOOM.COM