From c54c8fae2713a4a4e92ceaabba9695dfe411c744 Mon Sep 17 00:00:00 2001 From: "Md. Zaber Al Hamid" <86970972+mdzaberalhamid@users.noreply.github.com> Date: Fri, 21 Jul 2023 19:21:37 +0600 Subject: [PATCH] Update hex.js --- 01-color-flipper/hex.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/01-color-flipper/hex.js b/01-color-flipper/hex.js index e69de29..cb5743b 100644 --- a/01-color-flipper/hex.js +++ b/01-color-flipper/hex.js @@ -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); +}