javascript 需要一个标识符,而是看到了“else”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16782382/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Expected an identifier and instead saw 'else'
提问by user2426658
if(userThree === "Yes");
{
console.log("You go to your car and realize you've left it unlocked.);
}
else;
{
console.log("You continue to eat your meal.");
}
I put this onto JS Bin, but it continues to say: Expected an identifier and instead saw 'else'. Expected an assignment or function call and instead saw an expression.
我把它放到 JS Bin 上,但它继续说:期望一个标识符,而是看到了“else”。期望赋值或函数调用,却看到了一个表达式。
I don't know how to fix this
我不知道如何解决这个问题
回答by Supericy
In your first console.log, your string isn't fully quoted:
在您的第一个 console.log 中,您的字符串没有被完全引用:
"You go to your car and realize you've left it unlocked." // <- string needs to end with a quotation mark
Also, having semicolons in these (see below) positions won't give you your desired result.
此外,在这些(见下文)位置使用分号不会给你想要的结果。
if(userThree === "Yes"); <-
else; <-
回答by dasblinkenlight
You are missing a closing doublequote in the line below:
您在下面的行中缺少结束双引号:
console.log("You go to your car and realize you've left it unlocked.);
// Here--------------^
You also need to remove semicolons after if
and else
.
您还需要删除if
和之后的分号else
。