Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1389 How can I detect whether a number is odd or even?

You are here: irt.org | FAQ | JavaScript | Number | Q1389 [ previous next ]

Try:

<script language="JavaScript"><!--
function isEven(x) { return (x%2)?false:true; }
function isOdd(x) { return !isEven(x); }

for (var i=0; i < 100; i++)
    document.write(i + ': even - ' + isEven(i) + ', odd - ' + isOdd(i) + '<br>');
//--></script>

©2018 Martin Webb