Project 2 from 25 projects(Random color Generator)

 1 Created a component random-color-generate.

2 Created few buttons for HEX RGB and Generate a color.

3 Made 2 usestates for setTypeOfColor and setColor.

4 Added OnClicks with few handlers.

While on click clicking on hex, the type of color is set to "hex" and on click clicking the rgb the type of color is set to "rgb". And on click clicking the Generate a color, if type of color is hex then handleRandomHexColor function takes place else handleRandomRgbColor function is executed.

5 Inside the function handleRandomHexColor a constant hex is made with with an array of values.

6 A function is made "random" where random values of props (length) is generated.

7 Now we work on the function handleRandomHexColor ; we make a variable hexColor with the value"#" and a loop where hexColor is added with function "random" with the length of hex.We make the setColor to hexColor.

8 Now we work on the function handleRandomRgbColor ; we make 3 constants r, g, b  where we call the function random with length of 256 in all of them.

9 We then setColor to when handleRandomRgbColor is in action.

10 We set a useEffect so that when typeOfColor is rgb , handleRandomRgbColor is in action else handleRandomHexColor is in place.

11 Now on click of Hex Color, typeOfColor is set to hex ; on click of Rgb Color , typeOfCOlor is set to rgb and while clicking random color, a random color is generated.

Comments

Popular posts from this blog

Project 4 of 25 Projects (Infinite Scroll)