File tree Expand file tree Collapse file tree 3 files changed +63
-0
lines changed
15. Background Color Changer Expand file tree Collapse file tree 3 files changed +63
-0
lines changed Original file line number Diff line number Diff line change 1+ const btn = document . getElementById ( "btn" ) ;
2+ let hex = document . getElementById ( "hexCode" ) ;
3+
4+ function randomColor ( ) {
5+ let letters = "0123456789ABCDEF" ;
6+ let color = "#" ;
7+ for ( let i = 0 ; i < 6 ; i ++ ) {
8+ color += letters [ Math . floor ( Math . random ( ) * 16 ) ] ;
9+ }
10+ return color ;
11+ }
12+
13+ btn . addEventListener ( "click" , ( ) => {
14+ document . body . style . backgroundColor = randomColor ( ) ;
15+ hex . innerHTML = randomColor ( ) ;
16+ } ) ;
Original file line number Diff line number Diff line change 1+ < html lang ="en ">
2+ < head >
3+ < meta charset ="UTF-8 " />
4+ < meta http-equiv ="X-UA-Compatible " content ="IE=edge " />
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
6+ < title > Random Background Color Changer</ title >
7+ < link rel ="stylesheet " href ="style.css " />
8+ </ head >
9+ < body >
10+ < button id ="btn "> Click Me</ button >
11+ < h2 id ="hexCode "> #8a2be2</ h2 >
12+
13+ < script src ="app.js "> </ script >
14+ </ body >
15+ </ html >
Original file line number Diff line number Diff line change 1+ body {
2+ background : blueviolet;
3+ min-height : 90vh ;
4+ display : flex;
5+ flex-direction : column;
6+ justify-content : center;
7+ align-items : center;
8+ transition : 0.3s cubic-bezier (0.215 , 0.61 , 0.355 , 1 );
9+ }
10+
11+ h2 {
12+ color : # fff ;
13+ font-weight : 200 ;
14+ }
15+
16+ button {
17+ padding : 15px ;
18+ background : transparent;
19+ border : 2px solid white;
20+ color : # fff ;
21+ transition : 0.8s cubic-bezier (0.175 , 0.885 , 0.32 , 1.275 );
22+ }
23+
24+ button : hover {
25+ background : # fff ;
26+ color : # 000 ;
27+ cursor : pointer;
28+ }
29+
30+ button : active {
31+ padding : 5px ;
32+ }
You can’t perform that action at this time.
0 commit comments