Solved

# JS noob question about identifying odd number

Posted on 2004-04-29
Medium Priority
255 Views
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
Question by:skinnyl
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2

LVL 10

Expert Comment

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

ID: 10954440

if( i % 2 == 1 )
0

Author Comment

ID: 10954530
excellent!

just what i was after.

Ta

Jack
0

## Featured Post

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…
###### Suggested Courses
Course of the Month9 days, 2 hours left to enroll