Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Generate Random Hex Code

const randomHex = () => `#${Math.floor(Math.random() * 0xffffff).toString(16).padEnd(6, "0")}`;

console.log(randomHex());
// Result: #92b008
Comment

Random Hex Color Code Generator

<!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>
Comment

Generate a Random Hex Color

const hexColor = () => "#" + Math.floor(Math.random() * 0xffffff).toString(16).padEnd(6, '0')
Comment

Random hexa color code

//Random hexa decimal code
'#'+Math.floor(Math.random()*16777215).toString(16);
Comment

generate a hex colour, random hex code

const randomHexColor = () =>
  `#${Math.random().toString(16).slice(2, 8).padEnd(6, '0')}`;
console.log(randomHexColor()); // #7a10ba (varies)
console.log(randomHexColor()); // #65abdc (varies)
Comment

Random HEX color

const hexColor = () => `#${Math.floor(Math.random() * 0xffffff).toString(16).padEnd(6, "0")}`;
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript every other element in array 
Javascript :: how to find the index of a value in an array in javascript 
Javascript :: jquery confirm dialog 
Javascript :: You need to authorize this machine using `npm adduser` 
Javascript :: express async errors 
Javascript :: trunc number javascript 
Javascript :: play audio javascript 
Javascript :: white screen issue in react native splashscreen 
Javascript :: how to convert array to uppercase in javascript 
Javascript :: if select option disabled jquerz 
Javascript :: lodash remove undefined values from array 
Javascript :: react router next page top 
Javascript :: discord.js pick random from array 
Javascript :: js today timestamp 
Javascript :: string repeat codewars javascript 
Javascript :: js transitions 
Javascript :: store data in array jquery 
Javascript :: float to currency 
Javascript :: how create an index mongodb 
Javascript :: react js materilize 
Javascript :: js desktop notification 
Javascript :: regex contains string in end 
Javascript :: Read text file in vanilla JS 
Javascript :: export aab react native 
Javascript :: convert base64 to image nodejs 
Javascript :: js maximum number value 
Javascript :: json.stringify parameters 
Javascript :: remove attribute onclick jquery 
Javascript :: javascript merge two objects 
Javascript :: jquery insertafter 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =