From 50a87783b6d24f617bf75a6d713eea5026baf072 Mon Sep 17 00:00:00 2001 From: lolabird Date: Fri, 10 Nov 2023 07:49:31 -0700 Subject: [PATCH] Add logic for filtering out rgb button --- script.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/script.js b/script.js index eede3a7..0f75ef9 100644 --- a/script.js +++ b/script.js @@ -7,6 +7,7 @@ const buttons = document.querySelectorAll("button"); let colorValue = "black"; let numGrid = gridSlider.value; let sliderLabel = document.querySelector("#sliderLabel"); +let isRgb; buttons.forEach((button) => { button.addEventListener ("click", changeColor); @@ -46,12 +47,22 @@ function getGridDimensions() { } function colorGrid() { - this.style.background = colorValue; + if (isRgb) { + this.style.background = rgbColor(); + } else { + this.style.background = colorValue; + } } function changeColor() { const buttonID = this.id; + if (buttonID === "rgbColor") { + isRgb = true; + } else { + isRgb = false; + } + switch (buttonID) { case "rgbColor": colorValue = rgbColor();