[英]JavaScript IF / ELSE error - expected an identifier
I'm trying to learn JavaScript on Code Academy I am facing the following syntax problem. 我正在尝试在Code Academy上学习JavaScript,但遇到以下语法问题。 Tells me: 告诉我:
expected an identifier and instead saw 'else'. Missing ';' before statement
Here is the code: 这是代码:
If("Jon".length * 2 / (2+1) === 6);
{
console.log("The answer makes sense!");
}
else {
console.log("Error. Error. Error.");
}
Omit the ;
省略;
in If("Jon".length * 2 / (2+1) === 6);
在If("Jon".length * 2 / (2+1) === 6);
The syntax of if
is: if
的语法是:
if(condition) {
// what to happen
} else {
// what to happen
}
从if语句中删除分号。
You may try this: 您可以尝试以下方法:
If ("Jon".length * 2 / (2+1) == 6) {
console.log("The answer makes sense!");
} else {
console.log("Error. Error. Error.");
}
You have a semicolon ;
你有分号;
after you if
statement. 在您之后if
语句。 Remove it. 去掉它。 It should be: 它应该是:
if("Jon".length * 2 / (2+1) === 6) {
console.log("The answer makes sense!");
} else {
console.log("Error. Error. Error.");
}
The correct usage of the if
syntax is: if
语法的正确用法是:
if (condition) {
// Do something here
} else {
// For instances where the condition hasn't met do something else
}
remove ;
去除;
from 从
If("Jon".length * 2 / (2+1) === 6);
Remove semicolon ;
删除分号;
at the end of if statement. 在if语句的末尾。
Change 更改
If("Jon".length * 2 / (2+1) === 6);
To 至
if("Jon".length * 2 / (2+1) === 6)
The if
is in lowercase, and you need to remove the semicolon at the end of the if line. if
是小写字母,您需要在if行的末尾删除分号。
if("Jon".length * 2 / (2+1) === 6) {
console.log("The answer makes sense!");
} else {
console.log("Error. Error. Error.");
}
you have a semicolon to much. 你有很多分号。 it should be: 它应该是:
if (boolean statement) {
//do sth
}
else { }
currently your if statement ends directly after the boolean statement 当前,您的if语句在boolean语句之后直接结束
remove the semicolon behind 删除后面的分号
if("Jon".length * 2 / (2+1) === 6)**;**
additional write in in lower characters 用小写字母附加书写
Semicolons in JavaScript are used to seperate statements! JavaScript中的分号用于分隔语句!
In that case, remove the semicolon from this line and ensure if
is in lowercase : 在这种情况下,请从此行中删除分号 ,并确保if
为小写 :
if("Jon".length * 2 / (2+1) === 6);
A semicolon (;) separates JavaScript statements. 用分号(;)分隔JavaScript语句。
Normally you add a semicolon at the end of each executable statement. 通常,您在每个可执行语句的末尾添加一个分号。
Using semicolons also make it possible to write many statements on one line. 使用分号还可以在一行上写很多语句。
You have to remove the semicolon in your if statement. 您必须在if语句中删除分号。
Change your code 更改您的代码
From 从
If("Jon".length * 2 / (2+1) === 6);
To 至
If("Jon".length * 2 / (2+1) === 6)
And please check out if.. else statement in javascript . 并且请检查javascript中的if .. else语句 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.