Solved

JS noob question about identifying odd number

Posted on 2004-04-29
3
251 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

810 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