-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
25 lines (21 loc) · 837 Bytes
/
Copy pathscript.js
File metadata and controls
25 lines (21 loc) · 837 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
const button = document.querySelector("#colorButton");
const rgbColor = document.querySelector("#rgbColor");
const body = document.body;
// random color generator function
function randomColorGenerator(){
const red = Math.floor(Math.random()*256);
const green = Math.floor(Math.random()*256);
const blue = Math.floor(Math.random()*256);
// assigning all three colors in one variable --> finalColor
const finalColor = `rgb(${red}, ${green}, ${blue})`;
return finalColor;
}
// adding event listener on the button
button.addEventListener("click", ()=>{
// calling randomColor function
const randomColor = randomColorGenerator();
// changing body color
body.style.backgroundColor = randomColor;
// updating rgb value on screen
rgbColor.textContent = randomColor;
})