Skip to content

Instantly share code, notes, and snippets.

@DeoluA
Created June 7, 2019 17:35
Show Gist options
  • Save DeoluA/48c0347d45c0f6d00a1ad5f684aa3ba8 to your computer and use it in GitHub Desktop.
Save DeoluA/48c0347d45c0f6d00a1ad5f684aa3ba8 to your computer and use it in GitHub Desktop.
JavaScript Random Colour/Color Generator (Hex values)
var rand_hex_col_gen = function(){
// do the numbers first
var options = [];
for(var i=0; i<10; i++){
options.push(i.toString());
};
// add letters
options = [].concat.apply(options, ["a", "b", "c", "d", "e", "f"]);
// loop through till you get a col
var chosen_col = "#";
while(chosen_col.length < 7){
chosen_col += options[Math.floor(Math.random() * options.length)]
};
// return the final value
return chosen_col;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment