Created
June 7, 2019 17:35
-
-
Save DeoluA/48c0347d45c0f6d00a1ad5f684aa3ba8 to your computer and use it in GitHub Desktop.
JavaScript Random Colour/Color Generator (Hex values)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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