Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/473.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语句中使用逻辑AND时会出现意外的标记?_Javascript_If Statement_Unexpected Token - Fatal编程技术网

Javascript 为什么在if语句中使用逻辑AND时会出现意外的标记?

Javascript 为什么在if语句中使用逻辑AND时会出现意外的标记?,javascript,if-statement,unexpected-token,Javascript,If Statement,Unexpected Token,我试图使用if语句循环遍历一个数组,该数组包含中具有多个属性值的构造函数实例 我正在使用逻辑AND运算符确保满足2个条件,但我不断收到未捕获SyntaxError的消息: 位于第二个逻辑条件运算符的意外令牌 我以前用过这个,从来没有过这个问题,所以现在不明白为什么?我仍在学习Javascript,但这似乎应该是非常直接的 我尝试删除消息抛出的运算符,但这给我留下了一个条件 class Streets { constructor(name, area) { this.nam

我试图使用if语句循环遍历一个数组,该数组包含中具有多个属性值的构造函数实例

我正在使用逻辑AND运算符确保满足2个条件,但我不断收到未捕获SyntaxError的消息:

位于第二个逻辑条件运算符的意外令牌

我以前用过这个,从来没有过这个问题,所以现在不明白为什么?我仍在学习Javascript,但这似乎应该是非常直接的

我尝试删除消息抛出的运算符,但这给我留下了一个条件

class Streets {
    constructor(name, area) {
        this.name = name;
        this.area = area;
    }
}

const street1 = new Streets('Brookwood Glen', 500);
const street2 = new Streets('Abbey Street', 1500);
const street3 = new Streets('Grafton Street', 3000);
const street4 = new Streets('Drury Street', 5000);

const totalStreets = [street1, street2, street3, street4];

function getStreetSize() {
    for(let cur of totalStreets) {
        if(cur.area > 0 && <= 500) { //This line is where I get the error message
            console.log(`${cur.name} has a length of ${cur.size}m and is a tiny street.`);
        } else if(cur.area > 500 && =< 1000) {
            console.log(`${cur.name} has a length of ${cur.size}m and is a small street.`);
        } else if(cur.area > 1000 && =< 1500) {
            console.log(`${cur.name} has a length of ${cur.size}m and is a normal street.`);
        } else if(cur.area > 1500 && =< 2000) {
            console.log(`${cur.name} has a length of ${cur.size}m and is a big street.`);
        } else if(cur.area > 2000) {
            console.log(`${cur.name} has a length of ${cur.size}m and is a huge street.`);
        } else {
            console.log(`${cur.name} is a normal street`);
    }
}
}
class街道{
建造商(名称、面积){
this.name=名称;
这个面积=面积;
}
}
康斯特街1=新街道('Brookwood Glen',500);
const street2=新街道(“阿比街”,1500);
const street3=新街道(“格拉夫顿街”,3000);
const street4=新街道(“德鲁里街”,5000);
const totalStreets=[street1、street2、street3、street4];
函数getStreetSize(){
对于(让totalStreets的cur){
如果(当前面积>0&&500&&1000){
log(`cur.name}的长度为${cur.size}m,是一条小街。`);
}否则,如果(当前面积>1000&&=<1500){
log(`cur.name}的长度为${cur.size}m,是一条普通街道。`);
}否则如果(当前面积>1500&=<2000){
log(`cur.name}的长度为${cur.size}m,是一条大街。`);
}否则,如果(当前面积>2000){
log(`cur.name}的长度为${cur.size}m,是一条巨大的街道。`);
}否则{
log(`${cur.name}是一条普通街道`);
}
}
}

我希望for循环遍历“totalStreets”数组中的元素,并计算“area”值是否在2个条件之间,并将相应的语句打印到控制台,但它不允许我使用小于/大于运算符。

和的每一侧都需要一个有效的表达式

=<1000
不是有效的表达式,缺少左侧

不能从另一个表达式上的codeLHS/code>中暗示
=
cur.area > 500 && cur.area =< 1000
cur.area>500&&cur.area=<1000

如果(cur.area>0&&cur.area
你甚至找到了有问题的那行,你需要把
cur.area设置为
0&&cur.area
。你试过读代码吗?它甚至是你的代码吗?
我以前用过这个,从来没有遇到过这个问题
我对此表示怀疑。否决的原因:答案是在其他人之后发布的(正确)答案。这个答案并不试图解释什么是错误的。它只是指示其他人使用另一段代码。重复其他人编写的内容只是为了寻找堆栈溢出点,这很难看。我们不是来寻找点,而是来帮助别人。我不知道你从复制其他人的答案中可以得到什么。。