Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaScript IF/ELSE错误-应为标识符_Javascript_Identifier - Fatal编程技术网

JavaScript IF/ELSE错误-应为标识符

JavaScript IF/ELSE错误-应为标识符,javascript,identifier,Javascript,Identifier,我试图在代码学院学习JavaScript,但我面临以下语法问题。告诉我: 应为标识符,而应为“else”。缺少“;”在语句之前 代码如下: If("Jon".length * 2 / (2+1) === 6); { console.log("The answer makes sense!"); } else { console.log("Error. Error. Error."); } 从if语句中删除分号。您可以尝试以下操作: If ("Jon".length *

我试图在代码学院学习JavaScript,但我面临以下语法问题。告诉我:

应为标识符,而应为“else”。缺少“;”在语句之前

代码如下:

If("Jon".length * 2 / (2+1) === 6);

{
    console.log("The answer makes sense!");

} 
else {

    console.log("Error. Error. Error.");
}

从if语句中删除分号。

您可以尝试以下操作:

If ("Jon".length * 2 / (2+1) == 6) {
    console.log("The answer makes sense!");
} else {    
    console.log("Error. Error. Error.");
}

省略
If(“Jon.”长度*2/(2+1)==6时,编码>in

如果
的语法是:

if(condition) {
  // what to happen
} else {
  // what to happen
}

您有一个分号
在您的
if
语句之后。移除它。应该是:

if("Jon".length * 2 / (2+1) === 6) {

   console.log("The answer makes sense!");

} else {

    console.log("Error. Error. Error.");

}
if (boolean statement) {
//do sth
}
else { }
if
语法的正确用法是:

if (condition) {
   // Do something here
} else {
   // For instances where the condition hasn't met do something else
}

删除
来自

If("Jon".length * 2 / (2+1) === 6);

删除分号
在if语句的末尾

改变

If("Jon".length * 2 / (2+1) === 6);  


if
是小写的,您需要删除if行末尾的分号

if("Jon".length * 2 / (2+1) === 6) {
    console.log("The answer makes sense!");
} else {

    console.log("Error. Error. Error.");
}

你有一个分号表示很多。应该是:

if("Jon".length * 2 / (2+1) === 6) {

   console.log("The answer makes sense!");

} else {

    console.log("Error. Error. Error.");

}
if (boolean statement) {
//do sth
}
else { }

当前,if语句直接在boolean语句之后结束

请删除后面的分号

if("Jon".length * 2 / (2+1) === 6)**;**

JavaScript中的其他小写字符分号写入用于分隔语句

在这种情况下,从此行中删除分号,如果
是小写的,请确保

if("Jon".length * 2 / (2+1) === 6);
JavaScript语句之间用分号(;)分隔

通常在每个可执行语句的末尾添加分号

使用分号还可以在一行上写许多语句

您必须删除if语句中的分号

更改代码


请检查。

在If之后删除分号将大写字母If改为If此问题将吸引数百个答案:psiIndicate:
控制台。日志不跨浏览器。旧的浏览器会导致JavaScript错误。@ShivanRaptor他说他正在编解码器,所以别担心……非常感谢Yagnesh!这真的很有帮助,很有帮助Vogel612@user3106983实际上,你不需要感谢所有贴出答案的人。。张贴答案的人通常认为他们是有帮助的。如果不是这样的话,你应该只发表评论,还要说明原因。如果你做得对,他们可以改进他们的答案,这可能会有所帮助
If("Jon".length * 2 / (2+1) === 6)