File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- <!-- placeholder file -->
1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+
4+ < head >
5+ < meta charset ="UTF-8 ">
6+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
7+ < title > Just Practice</ title >
8+ < link rel ="stylesheet " href ="style.css ">
9+ </ head >
10+
11+ < body >
12+ < div class ="container ">
13+ < h1 > Click the button to change the background color</ h1 >
14+ < p id ="colorCode "> </ p >
15+ < button id ="colorBtn "> Click Here</ button >
16+ </ div >
17+ < script src ="script.js "> </ script >
18+ </ body >
19+
20+ </ html >
Original file line number Diff line number Diff line change 1+ const colorBtn = document . getElementById ( "colorBtn" ) ;
2+
3+ function getRandomColor ( ) {
4+ const random = "#" + Math . floor ( Math . random ( ) * 16777215 ) . toString ( 16 ) ;
5+ return random ;
6+ }
7+
8+ colorBtn . addEventListener ( "click" , ( ) => {
9+ const color = getRandomColor ( ) ;
10+ document . body . style . backgroundColor = color ;
11+ document . getElementById ( "colorCode" ) . textContent = `Current Color: ${ color } ` ;
12+ } ) ;
Original file line number Diff line number Diff line change 1+ body {
2+ font-family : sans-serif;
3+ text-align : center;
4+ padding : 50px 20px ;
5+ transition : background-color 0.3s ease;
6+ }
7+
8+ .container {
9+ border : 5px solid black;
10+ border-radius : 50px ;
11+ height : 200px ;
12+ width : 25% ;
13+ margin : auto;
14+ background-color : white;
15+ }
16+
17+ h1 {
18+ margin-top : 30px ;
19+ }
20+
21+ button {
22+ font-size : 20px ;
23+ padding : 10px 30px ;
24+ font-weight : 600 ;
25+ border : none;
26+ border-radius : 30px ;
27+ background-color : crimson;
28+ color : white;
29+ cursor : pointer;
30+ }
31+
32+ p {
33+ font-size : 15px ;
34+ color : cornflowerblue;
35+ }
You can’t perform that action at this time.
0 commit comments