0

when using (count/2) for giving background color in div, it applied for alternative boxes. But i want to give div background for first three boxes same color then for the next three boxes diff color then again for the next three boxes the first color then next three boxes the second color.

The alternative color should be applied for three boxes once. Please clarify this one

0

2 Answers 2

2

You can use modulo

var c;
if (count % 6 < 3)
  // color one
  c = '#fff';
else
  // color two
  c = '#ccc';

Or as a one-liner

var c = count % 6 < 3 ? '#fff' : '#ccc';
Sign up to request clarification or add additional context in comments.

Comments

0

Try something like

k=0, Color=Red

while()
{
    if(k == 3)
    {
      k=0;
     if(Color == Red) Color=Green
     else Color = Red

    }
    else
   {
     k++;
   }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.