File tree Expand file tree Collapse file tree 3 files changed +60
-0
lines changed Expand file tree Collapse file tree 3 files changed +60
-0
lines changed Original file line number Diff line number Diff line change 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 > Random Color Generator</ title >
8+ < link rel ="stylesheet " href ="style.css ">
9+ </ head >
10+
11+ < body >
12+ < div class ="container ">
13+ < div class ="color-box " id ="colorBox "> </ div >
14+ < button onclick ="changeColor() "> Generate Random Color</ button >
15+ </ div >
16+
17+ < script src ="script.js "> </ script >
18+ </ body >
19+
20+ </ html >
Original file line number Diff line number Diff line change 1+ function getRandomColor ( ) {
2+ const letters = '0123456789ABCDEF' ;
3+ let color = '#' ;
4+ for ( let i = 0 ; i < 6 ; i ++ ) {
5+ color += letters [ Math . floor ( Math . random ( ) * 16 ) ] ;
6+ }
7+ return color ;
8+ }
9+
10+ function changeColor ( ) {
11+ const colorBox = document . getElementById ( 'colorBox' ) ;
12+ const randomColor = getRandomColor ( ) ;
13+ colorBox . style . backgroundColor = randomColor ;
14+ colorBox . textContent = `Color: ${ randomColor } ` ;
15+ }
16+
Original file line number Diff line number Diff line change 1+ body {
2+ display : flex;
3+ justify-content : center;
4+ align-items : center;
5+ height : 100vh ;
6+ margin : 0 ;
7+ }
8+
9+ .container {
10+ text-align : center;
11+ }
12+
13+ .color-box {
14+ width : 200px ;
15+ height : 200px ;
16+ margin : 20px auto;
17+ border : 2px solid black;
18+ }
19+
20+ button {
21+ font-size : 18px ;
22+ padding : 10px 20px ;
23+ cursor : pointer;
24+ }
You can’t perform that action at this time.
0 commit comments