Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 3543

# This is MOD?

I assume Javascript doesn't have a Mod function.  I found this on the web:

function Mod(a, b) { return Math.floor(a/b)*b }

Here's my code:

for(y=0;y<oGrid.Rows.length;y++) {
var row = oGrid.Rows.getRow(y);
for(x=0;x<row.Band.Columns.length;x++) {
var cell = row.getCell(x);
if (Mod(y,2) == 0 ) {
cell.Element.style.backgroundColor = "#E0FFFF";
cell.Element.style.color = "blue";
} else {
cell.Element.style.backgroundColor = "#FFFFFF";
cell.Element.style.color = "blue";
}
}
}

This line:

if (Mod(y,2) == 0 ) {

This doesn't work they way I'd expect Mod to work.  What the above code is attempting to do is alternate row colors in a grid.  In runtime when I click on a row, the first two rows are one color and rows 3-6 are the other color.  ???  This, to my knowledge, is how Mod should work:

Mod(0,2) = 0
Mod(1,2) = 1
Mod(2,2) = 0
Mod(3,2) = 1
Mod(4,2) = 0
Mod(5,2) = 1

But according to the code above:

Mod(0,2) = 0
Mod(1,2) = 0
Mod(2,2) = 1
Mod(3,2) = 1
Mod(4,2) = 1

Huh?  How can 2/2 <> 0?

0
MIKEV
1 Solution

Commented:
Yes Javascript has a mod function it's the percentage sign %

example

if (y%2 == 0 ) {