我做的石头,剪子,布上Codecademy网站JavaScript类,语法错误:意外标记{
我卡上的模块之一,不断收到“语法错误:意外的标记{”
这真的很奇怪!提示将不会运行,除非我删除所有大括号({}
)....但我需要花括号在if/else if/else语句中。
如果我删除第一个{
,则出现错误消息: “SyntaxError:Unexpected token}”。所以它只是注意到下一个大括号。
这里是我的代码:
var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
//All curly brackets are below this point
if (computerChoice >0, computerChoice <= .33) {
computerChoice = rock;
} else if (computerChoice > .33, computerChoice < .66) {
computerChoice = paper;
} else (computerChoice => .66, computerChoice <= 1) {
computerChoice = scissors;
}
看看产生错误的代码行。 – AD7six
无关:我强烈怀疑你的条件如你所期望的那样工作。只有最后一个实际上是“使用” –
*但是我需要在if/else if/else语句中使用大括号*实际上,您不需要。此外,只是好奇,但这个语法'if(condition1,condition2)',你是否在某处学习过,或者只是猜测它?为什么你要检查'> 0',什么时候会一直存在?在下一个条件中,当你已经知道它是什么时,为什么你要检查'> 0.33'?为什么你明显总是在检查“<= 1”? –