You should close the <td>
properly
<td bgcolor="mycolor"></td>
instead of
<td bgcolor="mycolor"</td>
then, you can set the background color of the <td>
programmtically like this
document.querySelector('[bgcolor="mycolor"]').style.backgroundColor = mycolor;
example -> http://jsfiddle.net/wvQJB/
or directly in the code you are writing to the page :
...
getHexadecimalValue(c) +
'</td><td style="background-color: '+mycolor+';"></td></tr>');
document.write('</table>');
Notice that bgcolor
is deprecated!! See -> https://developer.mozilla.org/en-US/docs/Fixing_common_validation_problems#The.C2.A0bgcolor_attribute_is_deprecated