This program produces a random background color by pressing a button. The colors are "X11 colors" from the CSS3 specification WebColors. I manually loaded these colors to the array, which is hopefully useful information for somebody. Of course, you can probably create the same array by doing a webscrape has anybody done this.
const btn = document.querySelector('button');
var items = ['MediumVioletRed', 'DeepPink', 'PaleVioletRed', 'HotPink',
'LightPink', 'Pink', 'DarkRed', 'Red', 'Firebrick', 'Crimson',
'IndianRed', 'LightCoral', 'Salmon', 'DarkSalmon',
'LightSalmon', 'OrangeRed', 'Tomato', 'DarkOrange', 'Coral',
'Orange', 'DarkKhaki', 'Gold', 'Khaki', 'PeachPuff', 'Yellow',
'PaleGoldenrod', 'Moccasin', 'PapayaWhip', 'LightGoldenrodYellow',
'LemonChiffon', 'LightYellow','Maroon', 'Brown', 'SaddleBrown', 'Sienna',
'Chocolate', 'DarkGoldenrod', 'Peru', 'RosyBrown', 'Goldenrod',
'SandyBrown', 'Tan', 'Burlywood', 'Wheat', 'NavajoWhite', 'Bisque',
'BlanchedAlmond', 'Cornsilk','DarkGreen', 'Green', 'DarkOliveGreen',
'ForestGreen', 'SeaGreen', 'Olive', 'OliveDrab', 'MediumSeaGreen',
'LimeGreen', 'Lime', 'SpringGreen', 'MediumSpringGreen', 'DarkSeaGreen',
'MediumAquamarine', 'YellowGreen', 'LawnGreen', 'Chartreuse', 'LightGreen',
'GreenYellow', 'PaleGreen', 'Teal', 'DarkCyan', 'LightSeaGreen',
'CadelBlue', 'DarkTurquoise', 'MediumTurquoise', 'Turquoise', 'Aqua',
'Cyan', 'AquaMarine', 'PaleTurquoise', 'LightCyan', 'Navy', 'DarkBlue',
'MediumBlue', 'Blue', 'MidnightBlue', 'RoyalBlue', 'SteelBlue',
'DodgerBlue', 'DeepSkyBlue', 'CornFlowerBlue', 'SkyBlue', 'LightSkyBlue',
'LightSteelBlue', 'LightBlue', 'PowderBlue', 'Indigo', 'Purple',
'DarkMagenta', 'DarkViolet', 'DarkSlateBlue', 'BlueViolet', 'DarkOrchid',
'Fuchsia', 'Magenta', 'SlateBlue', 'MediumSlateBlue',
'MediumOrchid', 'MediumPurple', 'Orchid', 'Violet', 'Plum',
'Thistle', 'Lavender', 'MistyRose', 'AntiqueWhite', 'Linen',
'Beige', 'WhiteSmoke', 'LavenderBlush', 'OldLace', 'AliceBlue',
'Seashell', 'GhostWhite', 'Honeydew', 'ForalWhite', 'Azure',
'MintCream', 'Snow', 'Ivory', 'White', 'Black', 'DarkSlateGray',
'DimGray', 'SlateGrey', 'Gray', 'LightSlateGray', 'DarkGray',
'Silver', 'LightGray', 'Gainsboro'];
function random_item(items)
{
return items[Math.floor(Math.random()*items.length)];
}
btn.addEventListener('click', () => {
const rndWebCol = (random_item(items));
document.body.style.backgroundColor = rndWebCol;
console.log(rndWebCol);
});