...

View Full Version : how to find if i is an even number?



scroots
01-12-2003, 08:46 PM
how can i find out if a variable which name is i is an even number?
Could i divide i by two and if the result has no decimal places its an even number.

anybody have any code for this?

scroots

mordred
01-12-2003, 08:52 PM
Two possibilities:



var num = 41;

if (num & 1 == 1) {
alert('is uneven');
}

if (num % 2 != 0) {
alert('is uneven');
}

scroots
01-12-2003, 09:06 PM
cheers for that
it works, hopefully i will find out tomorrow whether it works when i print it.

scroots



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum