Forum Moderators: open

Message Too Old, No Replies

Checking Numbers

         

circuitjump

4:16 pm on Feb 12, 2002 (gmt 0)

10+ Year Member



Hi all,

Quick JS question.

How can I go about writing an if statement that checks to see if a number is in increments of 10?

var tens = 10 or 20 or 30 or 40
if (number == tens) {
---- Execute code ----
} else {
---- Execute code ----
}

Something like that

Thanks

rpking

4:27 pm on Feb 12, 2002 (gmt 0)

10+ Year Member



Use the mod function %

if (number % 10 == 0){
---- Execute code ----
} else {
---- Execute code ----
}

circuitjump

4:37 pm on Feb 12, 2002 (gmt 0)

10+ Year Member



Thanks :)

circuitjump

9:05 pm on Feb 12, 2002 (gmt 0)

10+ Year Member



OK,
Now this is the new problem.

If rowIndex = an increment of ten, meaning if it equals 10, 20, 80, 100 or even 10,550 it will equal 0. But the problem is that I am doing a search page all in JS. Now say there is 246 values in the array variable, it displays ten at a time, when you click next, it displays the next ten. Now you have finally gotten to 240. When you click next it will display the last six without error right? Wrong, it displays the last six but gives you an error saying " Array[...] is not an object " Now I have to find a way to where it checks and sees if it is at the last of the arrays. If it is, then display the last six.

Here's the code

if (rowIndex != to the last value in the array variable && rowIndex % 10 == 0) {
var round_ten = 9;
} else {
var round_ten = 0;
}

Thanks

joshie76

6:32 pm on Feb 13, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



to get the current number of entries or items in an Array you can use

arrayname.length

where arrayname is the name of your array.