I've defined this function in a .js file. It's supposed to take a color, make it the background color in a table cell, and adjust the color of the text depending on whether the color is dark or light. What is wrong with the code?
function brighttest(season)
{
String fontColor = season;
// remove hash character from string
String rawFontColor = fontColor.substring(1,fontColor.length());
// convert hex string to int
int rgb = Integer.parseInt(rawFontColor, 16);
Color c = new Color(rgb);
float[] hsb = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null);
float brightness = hsb[2];
if (brightness < 0.5) {
document.write('<td width="25%" bgcolor="'+season+'">');
document.write ('<font color="#FFF8C6">'+season+'</font>'); //prints the value
} else {
document.write('<td width="25%" bgcolor="'+season+'">');
document.write ('<font color="#000000">'+season+'</font>'); //prints the value
}
}