Skip to content

Instantly share code, notes, and snippets.

Created January 7, 2020 15:50
What would you like to do?
Generate a random hexadecimal colour code in JavaScript
// Function to generate a 24-bit (non-alpha) colour (color, for US English speakers)
function makeRandomColour() {
const MAX_INT24 = 16777215;
return '#' + Math.round(Math.random() * MAX_INT24).toString(16);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment