Solved

JS noob question about identifying odd number

Posted on 2004-04-29
3
249 Views
Last Modified: 2008-03-10
hallo there,
                if i had a for loop like this (see below) how would i get it to check to see if the value of i was a odd number?

for(i=0;i < 4; i++)
{
 if(i is odd)
 {
   do this code;
 }
}

Cheers

Jack
0
Comment
Question by:skinnyl
  • 2
3 Comments
 
LVL 10

Expert Comment

by:eeBlueShadow
ID: 10954437
if( i % 2 = 1 )
{
...
}

the % sign is the modulo arithmetic operator, and means "the remainder when divided by"

_Blue
0
 
LVL 10

Accepted Solution

by:
eeBlueShadow earned 50 total points
ID: 10954440
oops, I made mistake #1

if( i % 2 == 1 )
0
 

Author Comment

by:skinnyl
ID: 10954530
excellent!

just what i was after.

Ta

Jack
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now