From 0dc41577724430cbbd179b4a191a8c97c173a521 Mon Sep 17 00:00:00 2001 From: Shailesh Parmar Date: Sat, 26 Sep 2020 15:35:06 +0530 Subject: [PATCH] updated js fil to desplay random color --- index.html | 2 +- index.js | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/index.html b/index.html index d8655d8..1ce43d9 100644 --- a/index.html +++ b/index.html @@ -8,7 +8,7 @@
- +
diff --git a/index.js b/index.js index d15beb5..7eec2dd 100644 --- a/index.js +++ b/index.js @@ -1,11 +1,15 @@ const bgcolor = ["red", "green", "blue"]; -console.log("object"); -const button = document.getElementsByTagName("button"); +const button = document.getElementById("btn"); -const changeBgColor = () => { - let count = Math.floor(Math.random() * 3); - document.body.style.backgroundColor = bgcolor[count]; - // console.log(bgcolor[count]); - // console.log(count); -}; +const changeBgColor = () => {}; + +button.addEventListener("click", () => { + let letter = "0123456789ABCDEF"; + let color = "#"; + for (let i = 0; i < 6; i++) { + color = color + letter[Math.floor(Math.random() * 16)]; + } + + document.body.style.backgroundColor = color; +});