anson920520 anson920520 - 1 year ago 120
Javascript Question

Check if integer ends with 0

How may I create an if-statement in order to check if an integer ends with 0?

For example, I'd like to have an if-statement like this:

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

Answer Source
      var test=107;
      var isEndsWithZero =test%10; 
        //Ends With 1-9,Do something
        alert("Ends With 1 to 9");
        //Ends With Zero ,Do something
        alert ("ends with zero");


isEndsWithZero=107%10 //7
Else part will get executed

JSFiddle Link :