Finished Hex page of Color Flipper, Color Flipper has all required feature completed

1-color-flipper
jason.zhu 2021-05-17 16:36:42 +10:00
parent a06d87ebaf
commit d5075f8a58
1 changed files with 16 additions and 0 deletions

View File

@ -1 +1,17 @@
const hex = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F"]; const hex = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F"];
// #f15025 orange color
const btn = document.getElementById('btn');
const color = document.querySelector(".color");
btn.addEventListener('click', function(){
let hexColor = '#';
for (let i = 0; i < 6; i++) {
hexColor += hex[getRandomNumber()];
}
color.textContent = hexColor;
document.body.style.backgroundColor = hexColor;
});
function getRandomNumber() {
return Math.floor(Math.random() * hex.length);
}