I have the following code which changes the background color of a table data cell according to the numerical value inside the cell.
While all other comparisons work as expected, (val<(-3000)) comparison never enters the block.
This is the code:
//Change Background Color for all P/L values
$(".PLcolors").each(function(index, value) {
var val = Number(parseFloat($(this).text(), 10));
console.log("value is " + val);
if (val === 0) {
$(this).css("background-color", "#DCDCDC");
} else if ((val => -3000) && (val <= 3000)) {
$(this).css("background-color", "#F0E68C");
} else if (val < (-3000)) {
$(this).css("background-color", "#FF0000");
} else if ((val > 3000)) {
$(this).css("background-color", "#008000");
}
});
the type of val variable is number.
valvariable?parseFloattakes only 1 argument. What gives youconsole.log($(this).text())?-4282exactly without any additional characters. The operation runs for multiple values so the format does not seem to be the main issue since for positive numbers > 3000 the comparison and coloring is performed as expected.