# 3 Colors on Table

Page 1 of 1

## 2 Replies - 522 Views - Last Post: 03 December 2012 - 04:25 PM

### #1 code098

Reputation: 0
• Posts: 7
• Joined: 25-October 12

# 3 Colors on Table

Posted 03 December 2012 - 12:54 PM

I am very close to being done with this. I just a small error that I can't fix. I got the colours to work for 10 and 25, but when I enter in 100 and 110 it gives all red, I need about a third of the table each red, green, and yellow. The function getValueCss(val,max) is where I display my three colours on the table.

```for (var i = start; i <= end; i++) {
MultTbl += '<tr>';
MultTbl += '<th>' + i + '</th>';
for (var j = 0; j < last; j++) {
var val = (i * (start + j));

MultTbl += '<td class="' + getValueCss(val) + '">' + val + '</td>';
}
MultTbl += '</tr>';
}

function getValueCss(val, max) {
max = end * end;
var d = (max / 3);
if (val < d)
return 'high'
else if (val < (d * 2))
return 'middle'
else
return 'low'
}

```

Is This A Good Question/Topic? 0

## Replies To: 3 Colors on Table

### #2 BetaWar

• #include "soul.h"

Reputation: 1372
• Posts: 7,886
• Joined: 07-September 06

## Re: 3 Colors on Table

Posted 03 December 2012 - 03:05 PM

I would suggest something like so:

```function getValueCSS(val, start, end){ // where start and end are the same as the loop parameters
var max = (end - start) / 3;
if(val < start + max){ // val < start + ((end - start) / 3)
return "high"; // this should perhaps be low, since it is the lower third of the interval
}
if(val < start + (max * 2)){ // val < start + ((end - start) * 2 / 3)
return "middle"; // middle third
}
return "low"; // highest third
}

```

Basically, you have to take into account your interval, instead of just the current value and maximum value.

NOTE - untested code.

Hopefully that makes sense.

### #3 code098

Reputation: 0
• Posts: 7
• Joined: 25-October 12

## Re: 3 Colors on Table

Posted 03 December 2012 - 04:25 PM

I figured it out thanks.