-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandomHexColor.js
22 lines (15 loc) · 935 Bytes
/
randomHexColor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**
* -------------------------------------------------------
* Programming Question : Generate random hex color
* -------------------------------------------------------
**/
// Q. WAF called randomHexColor that generates a random hexadecimal color code each time its called. The function shoul dreturn a string representing the random color code in the format '#RRGGBB', Where RR, GG, and BB are two-digit hexadecimal numbers representing the red, green, and blue components of the color, respectively.
//? The output color code should always start with # followed by six hexadecimal characters
//? The function should not take any parameters.
//? The generated color codes should be unique and evenly distributed across the entire range of possible hexadecimal codes.
//?
function randomHexColor() {
const hex = Math.random().toString(16).slice(2,8).padEnd(6,0);
return '#' + hex;
}
console.log(randomHexColor());