简体   繁体   中英

if else statement in my function does not work

I have the following 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". When I give the function a value between 55 and 67, I want it to print my number. This function does however not work. It print "Your number is x" no matter what number I pass as argument to the function. 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)
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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