i am new to programming. when i try this below function, it works well unless there is a blank cell in the column. if there is any blank value in the cell then it is not working and then entire page goes blank. please help me to fix.
function growth (cellvalue) {
var gcolor;
var numval=cellvalue
var val = Number(numval.replace("%",""));
if (val<0) {
gcolor = 'red';
} else if (val>0) {
gcolor = 'green';
}
return '<span class="cellWithoutBackground" style="background-color:' + gcolor + ';">' + cellvalue + '</span>';
};
i have also tried this below with not equal to null like this if (val !== null && val<0)
function growth (cellvalue) {
var gcolor;
var numval=cellvalue
var val = Number(numval.replace("%",""));
if (val !== null && val<0) {
gcolor = 'red';
} else if (val !== null && val>0) {
gcolor = 'green';
}
return '<span class="cellWithoutBackground" style="background-color:' + gcolor + ';">' + cellvalue + '</span>';
};
both works fine when there is no blank cell. but when there is a blank cell, it is not working. please help.
UPDATE
function growth (cellvalue) {
var numval=cellvalue
if(numval != null || numval != '' || numval != "")
{
var gcolor;
var val = Number(numval.replace("%",""));
if(val<0) {gcolor = 'red';}
else if(val >0) {gcolor = 'green';}
return '<span class="cellWithoutBackground" style="background-color:' + gcolor + ';">' + cellvalue + '</span>';
};
else{return '<span class="cellWithoutBackground" style="background-color:' + white + ';">' + cellvalue + '</span>';};