Answered by : fazeel-ahmed
const randomHex = () => `#${Math.floor(Math.random() * 0xffffff).toString(16).padEnd(6, "0")}`;
console.log(randomHex());
// Result: #92b008
Source : https://dev.to/saviomartin/20-killer-javascript-one-liners-94f | Last Update : Fri, 14 Jan 22
Answered by : md-emdadullah
//Random hexa decimal code
'#'+Math.floor(Math.random()*16777215).toString(16);
Source : | Last Update : Mon, 29 Aug 22
Answered by : splendid-sable-j03bhfia1t17
<!DOCTYPE html>
<html>
<head> <meta charset="utf-8"> <title>Random Hex Code Generator</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" type="text/css" href="style.css"> <link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Sans&display=swap" rel="stylesheet">
</head>
<body> <div class="flex-row-outer"> <div class="flex-row"> <span id="hexCode">#000000</span> <button class="colorBtn" onClick="GenerateCode()">Generate</button> </div> </div> <script type="text/javascript"> let body = document.querySelector("body"); let hexCode = document.querySelector("#hexCode"); body.style.backgroundColor = hexCode.innerText; function GenerateCode() { let RandomColor = ""; let Char = "0123456789abcdefghijklmnopqrstuvwxyz"; for(i = 0; i < 6; i++) { RandomColor = RandomColor + Char[Math.floor(Math.random() * 16)]; } hexCode.innerText = "#" + RandomColor; body.style.backgroundColor = "#" + RandomColor; } </script>
</body>
</html>
Source : https://blog.stackfindover.com/random-hex-color-code-generator/ | Last Update : Fri, 06 May 22
Answered by : sanjai-kumar-jano3p9htkmm
const randomHexColor = () => `#${Math.random().toString(16).slice(2, 8).padEnd(6, '0')}`;
console.log(randomHexColor()); // #7a10ba (varies)
console.log(randomHexColor()); // #65abdc (varies)
Source : | Last Update : Fri, 19 Aug 22
Answered by : rakshit-lakhatariya
{"tags":[{"tag":"p","content":"Generate random HEX color values "},{"tag":"textarea","content":"const RandomColor = () => \"#\" + Math.floor(Math.random() * 0xffffff).toString(16).padEnd(6, \"0\");\n const color = RandomColor();\n console.log(color); \/\/ #bd1c55","code_language":"javascript"}]}
Source : https://levelup.gitconnected.com/some-javascript-tips-to-make-you-look-more-like-a-master-aaea9f92fc3c | Last Update : Tue, 04 Apr 23
Answered by : gleaming-goose-sva0lixjdo4w
const randomHexColor = () => `#${Math.floor(Math.random() * 0xffffff).toString(16).padEnd(6, "0")}`
Source : | Last Update : Wed, 04 Jan 23
Answered by : rich-rhinoceros-i9ndqct06v35
const hexColor = () => "#" + Math.floor(Math.random() * 0xffffff).toString(16).padEnd(6, '0')
Source : https://livecodestream.dev/post/awesome-javascript-one-liners-to-look-like-a-pro/ | Last Update : Thu, 21 Apr 22
Answered by : mohammad-harun-or-rashid
const randomHexCode = () => `#${Math.floor(Math.random() * 0xffffff).toString(16).padEnd(6, "0")}`;
const getRndHexCode = randomHexCode();
Source : | Last Update : Tue, 27 Dec 22
Answered by : imam-hossain
const hexColor = () => `#${Math.floor(Math.random() * 0xffffff).toString(16).padEnd(6, "0")}`;
Source : https://devdojo.com/codewithsnowbit/7-javascript-one-liners-to-look-like-a-pro | Last Update : Mon, 07 Mar 22