Odd/Even

1. John Drake Guest

## Odd/Even

What is the syntax for discovering if a number is odd or even? What value does this syntax return (does it return the str "odd" or "even")?<BR><BR>Thanks for you help.

2. Senior Member
Join Date
Dec 1969
Posts
261

## RE: Odd/Even

result=Yournumber mod 2<BR>if result is 0 then it is even - anything else is odd<BR><BR>alternatively <BR><BR>if instr((yournumber2),".") then <BR>&#039;its odd!<BR>else<BR>&#039;its even<BR>end if <BR>

3. KPW Guest

## RE: Odd/Even

Use the MOD operator.<BR><BR>If num MOD 2 = 0 Then<BR>&#039; number is even<BR>Else<BR>&#039; number is odd<BR>End If<BR><BR>MOD returns the remainder of a division operation.

4. Senior Member
Join Date
Dec 1969
Posts
614

## RE: Odd/Even

You can write a function that uses the vbscript MOD (find the remainder) statement so,<BR><BR>Dim x<BR>x=10<BR>response.write (x mod 2) // returns 0 = even<BR><BR>x=11<BR>response.write (x mod 2) // returns 1 = therefore odd<BR>

5. Senior Member
Join Date
Dec 1969
Posts
19,082

## FYI 'mod' in JScript is %

10%2 = 0<BR>11%2 = 1<BR><BR>j

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•