File tree Expand file tree Collapse file tree 3 files changed +77
-0
lines changed
Source-Code/RandomColorGenerator Expand file tree Collapse file tree 3 files changed +77
-0
lines changed Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6+ < title > Document</ title >
7+ < link rel ="stylesheet " href ="style.css ">
8+ </ head >
9+ < body >
10+ < div class ="main ">
11+ < div class ="container ">
12+ < h3 id ="color-code "> #fff</ h3 >
13+ < button id ="btn "> Click me</ button >
14+ </ div >
15+ </ div >
16+ < script src ="script.js ">
17+
18+ </ script >
19+ </ body >
20+ </ html >
Original file line number Diff line number Diff line change 1+ const getColor = ( ) =>
2+ {
3+ const randomNumber = Math . floor ( Math . random ( ) * 1677215 ) ;
4+ const randomCode = "#" + randomNumber . toString ( 16 ) ;
5+ console . log ( randomNumber , randomCode ) ;
6+ document . body . style . backgroundColor = randomCode
7+ document . getElementById ( "color-code" ) . innerText = randomCode
8+ navigator . clipboard . writeText ( randomCode ) //Copy the color code to clipboard also
9+ }
10+ //function call
11+ document . getElementById ( "btn" ) . addEventListener (
12+ "click" ,
13+ getColor
14+ )
15+ //init call
16+ getColor ( ) ;
17+
Original file line number Diff line number Diff line change 1+ * {
2+ margin : 0 ;
3+ padding : 0 ;
4+ box-sizing : border-box;
5+ font-family : sans-serif;
6+ }
7+ body
8+ {
9+ transition : 1s ;
10+ }
11+ .main
12+ {
13+ width : 100% ;
14+ height : 100vh ;
15+ display : flex;
16+ justify-content : center;
17+ align-items : center;
18+ }
19+ .container
20+ {
21+ width : 30rem ;
22+ padding : 10px ;
23+ border-radius : 10px ;
24+ background-color : aliceblue;
25+ font-size : 40px ;
26+ text-align : center;
27+
28+
29+ }
30+ button {
31+ display : block;
32+ width : 100% ;
33+ background-color : black;
34+ color : white;
35+ border : none;
36+ border-radius : 5px ;
37+ font-size : 40px ;
38+ margin-top : 5px ;
39+
40+ }
You can’t perform that action at this time.
0 commit comments