Skip to content

Instantly share code, notes, and snippets.

@damilolaolatunji
Created February 3, 2021 14:50
Show Gist options
  • Select an option

  • Save damilolaolatunji/00ad1c09b053c69b9be38e32865a0aaa to your computer and use it in GitHub Desktop.

Select an option

Save damilolaolatunji/00ad1c09b053c69b9be38e32865a0aaa to your computer and use it in GitHub Desktop.
const hexValues = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F'];
const button = document.querySelector('.btn');
const body = document.querySelector('body');
const value = document.querySelector('.hexValue');
function changeHex() {
let hex = '#';
for (let i = 0; i < 6; i++) {
const index = Math.floor(Math.random() * hexValues.length);
hex += hexValues[index];
}
value.textContent = hex;
body.style.backgroundColor = hex;
}
button.addEventListener('click', changeHex);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment