From 08f2b9e5ab26cd46d4f53475b3e853bdd36e9305 Mon Sep 17 00:00:00 2001 From: Ayush Tiwari Date: Sun, 12 Sep 2021 18:09:49 +0530 Subject: [PATCH 1/2] improved range of colors --- css/style.css | 6 +++++- js/script.js | 10 +++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/css/style.css b/css/style.css index 463dc06..f7cf30f 100644 --- a/css/style.css +++ b/css/style.css @@ -1,3 +1,7 @@ button { - margin-top: 50vh + margin-top: 43vh +} +button{ + min-width: 200px; + height: 80px; } \ No newline at end of file diff --git a/js/script.js b/js/script.js index 803c165..97fcb4d 100644 --- a/js/script.js +++ b/js/script.js @@ -1,12 +1,16 @@ //Choose a random color const button = document.querySelector('button') const body = document.querySelector('body') -const colors = ['red', 'green', 'blue', 'yellow', 'pink', 'purple'] + +// const colors = ['red', 'green', 'blue', 'yellow', 'pink', 'purple']; body.style.backgroundColor = 'violet' button.addEventListener('click', changeBackground) function changeBackground(){ -const colorIndex= parseInt(Math.random()*colors.length) -body.style.backgroundColor = colors[colorIndex] +const red = parseInt(Math.random()*256); +const green = parseInt(Math.random()*256); +const blue = parseInt(Math.random()*256); + +body.style.backgroundColor = `rgb(${red}, ${green}, ${blue})`; } From 48b32feeba3310d74096a048f2fe8368f9c6b713 Mon Sep 17 00:00:00 2001 From: Ayush Tiwari Date: Fri, 1 Oct 2021 08:50:27 +0530 Subject: [PATCH 2/2] fixed BGcolor of button to contrast out of background --- js/script.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/js/script.js b/js/script.js index 97fcb4d..c094d84 100644 --- a/js/script.js +++ b/js/script.js @@ -12,5 +12,14 @@ const red = parseInt(Math.random()*256); const green = parseInt(Math.random()*256); const blue = parseInt(Math.random()*256); +let Bred = 255,Bgreen = 255,Bblue = 255,Btextcolor = 0; +if(red === 255 && green === 255 && blue === 255){ + [Bred,Bgreen,Bblue] = 0; + Btextcolor = 255; +} + +button.style.backgroundColor = `rgb(${Bred}, ${Bgreen}, ${Bblue})`; +button.style.Color = `rgb(${Btextcolor}, ${Btextcolor}, ${Btextcolor})`; + body.style.backgroundColor = `rgb(${red}, ${green}, ${blue})`; }