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 :: date.tolocaledatestring is not a function 
Javascript :: Javascript find element with focus 
Javascript :: toggle css class in javascript 
Javascript :: seconds to degrees 
Javascript :: javascript traverse 
Javascript :: array contains multiple js 
Javascript :: flattenDeep in es 6 without lodash 
Javascript :: fatal error: ineffective mark-compacts near heap limit allocation failed – javascript heap out of memory 
Javascript :: how to append rows in table using jquery each function 
Javascript :: jQuery CSS Classes 
Javascript :: first duplicate javascript 
Javascript :: roblox headshot image js 
Javascript :: pymongo add json to collection 
Javascript :: html string to object jquery 
Javascript :: javascript from method 
Javascript :: javascript transition 
Javascript :: express get raw path 
Javascript :: search no of item in array 
Javascript :: merge data to json js 
Javascript :: react materilize 
Javascript :: js make node with string 
Javascript :: react router multiple path 
Javascript :: chart js stacked bar group 
Javascript :: jquery select div in div 
Javascript :: reverse a date in javascript 
Javascript :: javascript add days to date 
Javascript :: get dirname to last directory node 
Javascript :: how to make a 2 value after point javascript 
Javascript :: tofixed currency in js 
Javascript :: sequelize order by 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =