From 34aa91359b0c13250c6127affbb4bda758fea8e8 Mon Sep 17 00:00:00 2001 From: lolabird Date: Thu, 9 Nov 2023 23:17:42 -0700 Subject: [PATCH] Randomize rgb color --- script.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/script.js b/script.js index 63e96a5..2449cbb 100644 --- a/script.js +++ b/script.js @@ -54,7 +54,7 @@ function changeColor() { switch (buttonID) { case "rgbColor": - colorValue = "red"; + colorValue = rgbColor(); break; case "whiteColor": colorValue = "white"; @@ -77,4 +77,14 @@ function changeColor() { } } +function rgbColor() { + let r = Math.floor(Math.random() * 255); + let g = Math.floor(Math.random() * 255); + let b = Math.floor(Math.random() * 255); + + let rgbCol = "rgb(" + r + "," + g+ "," + b +")"; + + return rgbCol; +} + createGrid(); \ No newline at end of file