If number ends with 1 do something

if-statement, javascript

Solution

Just check the remainder of division by 10:

if (day % 10 == 1) { 
  result = "dan";
} else {
  result = "dana";
}

`%` is the "Modulo" or "Modulus" Operator, unless you're using JavaScript, in which case it is a simple remainder operator (not a true modulo). It divides the two numbers, and returns the remainder.

Problem

I want to make something like this: ``` if(day==1 || day==11 || day==21 || day==31 || day==41 ......){ result="dan"; } else{ result="dana"; } ``` How can i do that with every number that ends with one and of course without writing all numbers?

Original source

Related problems