toHex()
// covert a color to hex
function toHex(dec) { // create list of hex characters var hexCharacters = "0123456789ABCDEF" // if number is out of range return limit if (dec < 0) return "00" if (dec > 255) return "FF" // decimal equivalent of first hex character in converted number var i = Math.floor(dec / 16) // decimal equivalent of second hex character in converted number var j = dec % 16 // return hexadecimal equivalent return hexCharacters.charAt(i) + hexCharacters.charAt(j) }