检查整数是否以 0 结尾

Ans*_*pta 3 javascript if-statement

如何创建 if 语句以检查整数是否以 0 结尾?

例如,我想要一个这样的 if 语句:

var test = 107; //107 is an example it'should some unknown number

if(test is xx1 - xx9){
  //do something
}
else if(test is xx0){
  //do something
}
Run Code Online (Sandbox Code Playgroud)

Cam*_*rds 7

if (test % 10) {
    // does not end with 0
} else {
    // ends with 0
}
Run Code Online (Sandbox Code Playgroud)


Ven*_*kat 5

      var test=107;
      var isEndsWithZero =test%10; 
      if(isEndsWithZero!==0)
      {
        //Ends With 1-9,Do something
        alert("Ends With 1 to 9");
      }
      else
      {
        //Ends With Zero ,Do something
        alert ("ends with zero");
      }
Run Code Online (Sandbox Code Playgroud)

例子:

test=107;
isEndsWithZero=107%10 //7
Else part will get executed
Run Code Online (Sandbox Code Playgroud)

JSFiddle 链接:https ://jsfiddle.net/nfzuaa44/