From d0561c3cb2e018e1b9dd9df273aa9f33e710118e Mon Sep 17 00:00:00 2001 From: Todd Carlson Date: Mon, 3 Aug 2020 17:45:54 -0600 Subject: [PATCH] Added working random color button. --- 1-color-flipper/setup/hex.html | 2 +- 1-color-flipper/setup/hex.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/1-color-flipper/setup/hex.html b/1-color-flipper/setup/hex.html index 4b6878b79..69d382fb8 100644 --- a/1-color-flipper/setup/hex.html +++ b/1-color-flipper/setup/hex.html @@ -17,7 +17,7 @@

color flipper

diff --git a/1-color-flipper/setup/hex.js b/1-color-flipper/setup/hex.js index 88aba8183..fa2618b23 100644 --- a/1-color-flipper/setup/hex.js +++ b/1-color-flipper/setup/hex.js @@ -1 +1,17 @@ const hex = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F"]; + +const btn = document.getElementById('btn') +const color = document.querySelector('.color') + +btn.addEventListener('click', ()=> { + let hexColor = '#' + for (let i = 0; i < 6; i++) { + hexColor += hex[getRandomNumber()] + } + color.textContent = hexColor + document.body.style.backgroundColor = hexColor +}) + +const getRandomNumber = ()=> { + return Math.floor(Math.random() * hex.length) +} \ No newline at end of file