-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated js fil to desplay random color
- Loading branch information
1 parent
2e5dc65
commit 0dc4157
Showing
2 changed files
with
13 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); |