I'm doing revision in preparation for my Web Development exam, and came across this question:
My answer:
function pallete() {
var components = ["00", "33", "66", "99", "CC", "FF"];
var context = document.body;
var tab = document.createElement('table');
for (i = 0; i < 6; i++) {
for (j = 0; j < 6; j++) {
var trow = document.createElement('tr');
for (f = 0; f < 6; f++) {
var thead = document.createElement('th');
thead.innerHTML = "#" + components[i] + components[j] + components[f];
thead.style.color = components[i] + components[j] + components[f];
trow.appendChild(thead);
}
tab.appendChild(trow);
}
}
context.appendChild(tab);
}
I tested the code on the browser, but nothing is coming up! I think my logic is perfect though... Not sure what went wrong here. Please give me any pointers, thank you very much!
Working example with
document.createElement
td
instead ofth
innerHTML
as assignmenttd.style.backgroundColor
instead oftd.style.color
#
in front of color values, like#003366