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
  • Last Modified:

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
Asked:
MIKEV
1 Solution
 
BatalfCommented:
Yes Javascript has a mod function it's the percentage sign %

example

if (y%2 == 0 ) {

instead of

if (Mod(y,2) == 0 ) {
0
 
MIKEVAuthor Commented:
Cool, thanks!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now