Skip to content

Commit

Permalink
Update hex.js
Browse files Browse the repository at this point in the history
  • Loading branch information
mdzaberalhamid authored Jul 21, 2023
1 parent 1c8f503 commit c54c8fa
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions 01-color-flipper/hex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const hex = [0,1,2,3,4,5,6,7,8,9,"a","b","c","d","e","f"];
// #f15025

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);
}

0 comments on commit c54c8fa

Please # to comment.