Skip to content

Instantly share code, notes, and snippets.

@DeoluA
Created June 7, 2019 17:35

Revisions

  1. DeoluA created this gist Jun 7, 2019.
    20 changes: 20 additions & 0 deletions rand_hex_col_gen.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    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;
    };