Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: Color Chart Script

1. ## Color Chart Script

I have been using this counting script for something else.

But now I want it to count from 0-65535, put those numbers inside small div tags and have those div tags have the background color of the number it is counting.

It would be nice if the div tags went across the page and wrapped like text and started a new row.

Maybe counting that far will use too much memory. If so I can put x amount on one page and more on another and so on.

I'm still kicking myself for not learning JavaScript when I got online years ago. It would have certainly been good to know now.

Code:
```<script type="text/javascript">
for(var count=0; count<=65535; count++)
{
document.write('<div style=background-color:&#>');
document.write(count + '; = </div>');
document.write('&#' + count + ';');
}
</script>```

2. You will need to turn the decimal values of the loop counter into hex. Something like this:-

Code:
```<script type="text/javascript">

for (var a = 0; a<=5; a++) {  // change 5 to 255 for final version
for (var b = 0; b<=5; b++) {  // change 5 to 255 for final version
for (var c = 0; c<=5; c++) {   // change 5 to 255 for final version

var hexa =  a.toString(16).toUpperCase();  // hex
var hexb =  b.toString(16).toUpperCase();  // hex
var hexc =  c.toString(16).toUpperCase();  // hex

if (hexa.length<2) {hexa = "0" + hexa}
if (hexb.length<2) {hexb = "0" + hexb}
if (hexc.length<2) {hexc = "0" + hexc}

var f = hexa+hexb+hexc;
document.write(f + "<br>")

}
}
}

</script>```
But I think you will find that 65535 <div>s choke the browser.

Quizmaster: Who wrote the William Tell Overture?
Contestant: Was it William Tell?

3. Thanks

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•