Skip to content

Commit

Permalink
updated js fil to desplay random color
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaileshParmar11 committed Sep 26, 2020
1 parent 2e5dc65 commit 0dc4157
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</head>
<body>
<div class="root">
<button onclick="changeBgColor()">Change Background Color</button>
<button id="btn">Change Background Color</button>
</div>
</body>

Expand Down
20 changes: 12 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -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;
});

0 comments on commit 0dc4157

Please sign in to comment.