Add logic for filtering out rgb button
This commit is contained in:
parent
d4a6b4037a
commit
50a87783b6
1 changed files with 12 additions and 1 deletions
11
script.js
11
script.js
|
|
@ -7,6 +7,7 @@ const buttons = document.querySelectorAll("button");
|
||||||
let colorValue = "black";
|
let colorValue = "black";
|
||||||
let numGrid = gridSlider.value;
|
let numGrid = gridSlider.value;
|
||||||
let sliderLabel = document.querySelector("#sliderLabel");
|
let sliderLabel = document.querySelector("#sliderLabel");
|
||||||
|
let isRgb;
|
||||||
|
|
||||||
buttons.forEach((button) => {
|
buttons.forEach((button) => {
|
||||||
button.addEventListener ("click", changeColor);
|
button.addEventListener ("click", changeColor);
|
||||||
|
|
@ -46,12 +47,22 @@ function getGridDimensions() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function colorGrid() {
|
function colorGrid() {
|
||||||
|
if (isRgb) {
|
||||||
|
this.style.background = rgbColor();
|
||||||
|
} else {
|
||||||
this.style.background = colorValue;
|
this.style.background = colorValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function changeColor() {
|
function changeColor() {
|
||||||
const buttonID = this.id;
|
const buttonID = this.id;
|
||||||
|
|
||||||
|
if (buttonID === "rgbColor") {
|
||||||
|
isRgb = true;
|
||||||
|
} else {
|
||||||
|
isRgb = false;
|
||||||
|
}
|
||||||
|
|
||||||
switch (buttonID) {
|
switch (buttonID) {
|
||||||
case "rgbColor":
|
case "rgbColor":
|
||||||
colorValue = rgbColor();
|
colorValue = rgbColor();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue