11<!DOCTYPE html>
22< html lang ="en ">
3+
34< head >
4- < meta charset ="UTF-8 ">
5- < title > Background Color Changer</ title >
6- < style >
7- body {
8- font-family : system-ui, Arial;
9- text-align : center;
10- transition : background-color 0.5s ease;
11- height : 100vh ;
12- display : flex;
13- justify-content : center;
14- align-items : center;
15- flex-direction : column;
16- }
17- button {
18- background : # 111827 ;
19- color : white;
20- border : none;
21- padding : 10px 16px ;
22- border-radius : 8px ;
23- font-size : 16px ;
24- cursor : pointer;
25- margin-top : 20px ;
26- }
27- # colorCode {
28- margin-top : 10px ;
29- font-size : 20px ;
30- font-weight : 600 ;
31- }
32- </ style >
5+ < meta charset ="UTF-8 ">
6+ < title > Background Color Changer</ title >
7+ < style >
8+ body {
9+ font-family : system-ui, Arial;
10+ text-align : center;
11+ transition : background-color 0.5s ease;
12+ height : 100vh ;
13+ display : flex;
14+ justify-content : center;
15+ align-items : center;
16+ flex-direction : column;
17+ }
18+
19+ button {
20+ background : # 111827 ;
21+ color : white;
22+ border : none;
23+ padding : 10px 16px ;
24+ border-radius : 8px ;
25+ font-size : 16px ;
26+ cursor : pointer;
27+ margin-top : 20px ;
28+ }
29+
30+ # colorCode {
31+ margin-top : 10px ;
32+ font-size : 20px ;
33+ font-weight : 600 ;
34+ }
35+ </ style >
3336</ head >
37+
3438< body >
35- < h2 > 🎨 Background Color Changer</ h2 >
36- < button id ="changeColorBtn "> Change Color</ button >
37- < p id ="colorCode "> #FFFFFF</ p >
38-
39- < script >
40- const button = document . getElementById ( "changeColorBtn" ) ;
41- const colorCode = document . getElementById ( "colorCode" ) ;
42-
43- function randomColor ( ) {
44- // Generate random hex color
45- const letters = "0123456789ABCDEF" ;
46- let color = "#" ;
47- for ( let i = 0 ; i < 6 ; i ++ ) {
48- color += letters [ Math . floor ( Math . random ( ) * 16 ) ] ;
49- }
50- return color ;
51- }
52-
53- button . addEventListener ( "click" , ( ) => {
54- const newColor = randomColor ( ) ;
55- document . body . style . backgroundColor = newColor ;
56- colorCode . textContent = newColor ;
57- colorCode . style . color = newColor ;
58- } ) ;
59- </ script >
39+ < h2 > 🎨 Background Color Changer</ h2 >
40+ < button id ="changeColorBtn "> Change Color</ button >
41+ < p id ="colorCode "> #FFFFFF</ p >
42+
43+ < script >
44+ const button = document . getElementById ( "changeColorBtn" ) ;
45+ const colorCode = document . getElementById ( "colorCode" ) ;
46+
47+ function randomColor ( ) {
48+ // Generate random hex color
49+ const letters = "0123456789ABCDEF" ;
50+ let color = "#" ;
51+ for ( let i = 0 ; i < 6 ; i ++ ) {
52+ color += letters [ Math . floor ( Math . random ( ) * 16 ) ] ;
53+ }
54+ return color ;
55+ }
56+
57+ button . addEventListener ( "click" , ( ) => {
58+ const newColor = randomColor ( ) ;
59+ document . body . style . backgroundColor = newColor ;
60+ colorCode . textContent = newColor ;
61+ colorCode . style . color = newColor ;
62+ } ) ;
63+
64+ setInterval ( ( ) => {
65+ const newColor = randomColor ( ) ;
66+ document . body . style . backgroundColor = newColor ;
67+ colorCode . textContent = newColor ;
68+ } , 1222 ) ;
69+ </ script >
6070</ body >
61- </ html >
71+
72+ </ html >
0 commit comments