Is there a way i can see if a number is even or odd?

The title is self explanatory, is that a way i can determine with scripts if a number is even or odd?

3 Likes
local is_even = x % 2 == 0

Check if the remainder after division of 2 is 0. If the remainder is 0 then its divisible by 2. If not, then its odd.

% is called remainder division (or modulus operator). If you remember from elementary when you learned division, you might have written remainders as something like “R …”. e.g.

5 / 2 = 2 R 1
= 2 + 1/2
= 2.5

So x % y would be the remainder of x / y (the part after the R)

23 Likes