-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
27 lines (22 loc) · 662 Bytes
/
index.js
File metadata and controls
27 lines (22 loc) · 662 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
26
27
const button = document.querySelector(".btn");
const title = document.querySelector(".title");
const body = document.querySelector("body");
function randomColor() {
let color ="#";
let letters = "0123456789ABCDEF";
for ( i=0; i<6; i++){
color += letters[Math.floor(Math.random()*16)];
}
return color
}
button.addEventListener("click", ()=>{
body.style.backgroundColor= randomColor();
})
button.addEventListener("click", ()=>{
title.innerText= "Hex-Color:" + randomColor()
})
body.addEventListener("keydown", (e)=>{
if(e.control==="space"){
body.style.backgroundColor=randomColor()
}
})