LA
Size: a a a
LA
АМ
DK
const generateColor = () => Math.random().toString(16).slice(2, 8)
PV
А
А
KB
KB
DE
KB
С
let colorGenerator = () => {
let nums = "0123456789ABCDEF";
let color = "#";
for (let i = 0; i < 6; i++) {
color += nums[Math.floor(Math.random() * 16)];
}
return color;
};
console.log(colorGenerator());
function shuffleStr(str) {
return str.split('').sort(() => Math.random() > 0.5 ? 1 : -1).join('');
}
const COLOR_TYPES = { HEX: 'HEX', RGB: 'RGB', HSLA: 'HSLA' };
function generateColor(colorType = COLOR_TYPES.HEX) {
if (colorType === COLOR_TYPES.HEX) {
const hexPrefix = '#';
const hexSymbols = '0123456789ABCDEF';
const randomHex = shuffleStr(hexSymbols).substr(0, 6);
return hexPrefix + randomHex;
}
throw new Error(`colorType ${colorType} is not supported`);
}
console.log(generateColor(COLOR_TYPES.HEX));
DE
DK
DK