4 Replies Latest reply on Sep 25, 2006 9:48 AM by Rothrock

# Odd and Even numbers

Is there a why to check to see if a number/variable is odd or even with a little action script? Somthing like:
if(pageNum == number.Even)...
• ###### 1. Re: Odd and Even numbers
to see if even...

if (pageNum % 2 == 0) {
...
}

• ###### 2. Re: Odd and Even numbers
Can you briefly explain how that string works?
• ###### 3. Re: Odd and Even numbers
The part with the %2 means "modulo 2". In effect it is the remainder left after you have divided an integer by 2. Evens will divide and leave no remainder, thus == 0 , or an odd will leave 1 as a remainer (==1). Thus you can determine if number is even fro whats left over , 1 or 2. Dont forget to make sure your numbers are whole integers using Math.round, Math.ceil, or Math.floor.
• ###### 4. Re: Odd and Even numbers
Actually (assuming pageNum is an integer) I think you can even do this:

if(pageNum % 2){}

Since that will evaluate to either 0 or 1. Zero is False and one is true so. You might need to:

if(Boolean(pageNum % 2)){}