简体   繁体   English

我的 function 中的 if else 语句不起作用

[英]if else statement in my function does not work

I have the following function:我有以下 function:

function checkNumber(x){
  if(2<x<13) {
    console.log("Your number is "+x) 
  } else if (55<x<67) {
    console.log(x)
  }
}

When I give the function a value between 2 and 13, I want it to print "Your number is x".当我给 function 一个介于 2 到 13 之间的值时,我希望它打印“你的号码是 x”。 When I give the function a value between 55 and 67, I want it to print my number.当我给 function 一个介于 55 和 67 之间的值时,我希望它打印我的号码。 This function does however not work.然而,这个 function 不起作用。 It print "Your number is x" no matter what number I pass as argument to the function.无论我将什么数字作为参数传递给 function,它都会打印“你的号码是 x”。 Why?为什么?

You can try this:你可以试试这个:

function checkNumber(x){
  if(2<x && x<13) {
    console.log("Your number is "+x) 
  } else if (55<x && x<67) {
    console.log(x)
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM