Using JavaScript I am trying to randomly generate a hexadecimal color code:
var color = '#'+(Math.random()*0xFFFFFF<<0).toString(16);
This almost works, but sometimes, if the randomly generated number is too low, the code doesn't put the leading '0' or '00' at the front of the hexadecimal code.
Is there a simple way to fix this?