Re: JavaScript test for even or odd number

by "Rossi Designs" <webmaster(at)rossidesigns.net>

 Date:  Sun, 12 Mar 2000 18:51:11 -0500
 To:  "Colin Dunn" <Colin.Dunn(at)las.ox.ac.uk>,
<hwg-techniques(at)hwg.org>
 References:  ac
  todo: View Thread, Original
test = num % 2;

if test =1 then num is odd, if it is zero then num is even

Rossi Designs
(904) 226-8979
P.O. Box 1084, Holly Hill, Florida 32125-1084
http://rossidesigns.net
----- Original Message -----
From: Colin Dunn <Colin.Dunn(at)las.ox.ac.uk>
To: <hwg-techniques(at)hwg.org>
Sent: Sunday, March 12, 2000 4:46 PM
Subject: JavaScript test for even or odd number


| Now I'm no programmer ....... but I'm developing a JavaScript application
| that requires a numerical value to be tested to determine if it's even or
| odd. I figured that the simplest way of doing this was to convert the
value
| to binary, eg:
|
| function number_check(value) {
|  var binary = value.toString(2);
|  if (binary.charAt(binary.length - 1) == "1") {
|   return false;
|  }
|  else {
|   return true;
|  }
| }
|
| I'd be interested to hear from anyone who can offer alternative solutions.
|
| TIA
|
| Colin
|

HWG hwg-techniques mailing list archives, maintained by Webmasters @ IWA