11const palette = document . querySelector ( '.palette' ) ;
22const generateButton = document . getElementById ( 'generateButton' ) ;
33
4- // Generate a random color in hex format (#RRGGBB)
54function getRandomColor ( ) {
65 const letters = '0123456789ABCDEF' ;
76 let color = '#' ;
@@ -11,7 +10,6 @@ function getRandomColor() {
1110 return color ;
1211}
1312
14- // Create and append a color card to the palette
1513function createColorCard ( ) {
1614 const colorCard = document . createElement ( 'div' ) ;
1715 colorCard . classList . add ( 'color-card' ) ;
@@ -21,8 +19,7 @@ function createColorCard() {
2119 <div class="hex-code">${ hexCode } </div>
2220 ` ;
2321 palette . appendChild ( colorCard ) ;
24-
25- // Add click event to copy hex code to clipboard
22+
2623 colorCard . addEventListener ( 'click' , ( ) => {
2724 const tempInput = document . createElement ( 'input' ) ;
2825 tempInput . value = hexCode ;
@@ -34,19 +31,16 @@ function createColorCard() {
3431 } ) ;
3532}
3633
37- // Generate a random color palette with a specified number of colors
3834function generatePalette ( numColors ) {
39- palette . innerHTML = '' ; // Clear existing colors
35+ palette . innerHTML = '' ;
4036 for ( let i = 0 ; i < numColors ; i ++ ) {
4137 createColorCard ( ) ;
4238 }
4339}
4440
45- // Event listener for the "Generate Colors" button
4641generateButton . addEventListener ( 'click' , ( ) => {
4742 const numColors = Math . floor ( Math . random ( ) * 4 + 1 ) * 2 * 2 ; // 10, 12, 14, or 16 colors
4843 generatePalette ( numColors ) ;
4944} ) ;
5045
51- // Initial palette generation
52- generatePalette ( 10 ) ; // You can start with any initial number of colors
46+ generatePalette ( 10 ) ;
0 commit comments