ATTN REGISTRARS! it.com domain sunrise starts on Jan 2nd! GET READY NOW

Javascript: random hex color

Catch.Club
I made this last year when I was bored, it is a simple javascript where you press a button and a random hex color shows up in the box, along with its number.

It is here online: http://www.therustybarrel.com/david/experiments/randhex.html

But here's the main code:


<script language="Javascript">
<!--
function genHex(){
colors = new Array(14)
colors[0]="0"
colors[1]="1"
colors[2]="2"
colors[3]="3"
colors[4]="4"
colors[5]="5"
colors[5]="6"
colors[6]="7"
colors[7]="8"
colors[8]="9"
colors[9]="a"
colors[10]="b"
colors[11]="c"
colors[12]="d"
colors[13]="e"
colors[14]="f"

digit = new Array(5)
color=""
for (i=0;i<6;i++){
digit=colors[Math.round(Math.random()*14)]
color = color+digit
}
document.getElementById('hexc').style.backgroundColor=color
document.getElementById('hexn').innerText="#"+color
}
//-->
</script>


<table>
<tr>
<td id="hexc" height="100" width="100"> </td><td id="hexn"></td>
</tr>
</table>
<form>
<input type="button" onClick="genHex();"value="Generate Random Color">
</form>

enjoy ^_^
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Impact
0
nice, lol. Doing fun things like that is wel, fun! :tu:
 
0
•••
0
•••
Impact
0
haha, while we are at it, you got any mroe you wanna share?
 
0
•••