what's wrong with this function?
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
}
}
Re: what's wrong with this function?
Quote:
Originally Posted by
victorsaur
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? :-?
What is the error?
Re: what's wrong with this function?
Moved to Other Programming Languages
javascript != java. Your code is javascript, and this is a java forum. You might try your luck on a javascript dedicated forum
Re: what's wrong with this function?
It causes all other links to images and text to not show up... and I'm sure that it is not calling the function itself, rather the function that has some error.