diff --git a/01_Day_JavaScript_Refresher/01_javascript_refresher.md b/01_Day_JavaScript_Refresher/01_javascript_refresher.md index 7d03fb4..5144354 100644 --- a/01_Day_JavaScript_Refresher/01_javascript_refresher.md +++ b/01_Day_JavaScript_Refresher/01_javascript_refresher.md @@ -1,3 +1,4 @@ +ls

30 Days Of React: JavaScript Refresher

diff --git a/Exercises/day-1/function-exercise-2and3.js b/Exercises/day-1/function-exercise-2and3.js index d383b71..58fd987 100644 --- a/Exercises/day-1/function-exercise-2and3.js +++ b/Exercises/day-1/function-exercise-2and3.js @@ -151,6 +151,20 @@ const userIdGenerator = () => { return id; }; +// Write a function generateColors which can generate any number of hexa or rgb colors. + +const generateColors = (type, count) => { + let colors = []; + for (let i = 0; i < count; i++) { + if (type === 'hexa') { + colors.push('#' + Math.floor(Math.random()*16777215).toString(16).padStart(6, '0')); + } else if (type === 'rgb') { + colors.push(`rgb(${Math.floor(Math.random()*256)}, ${Math.floor(Math.random()*256)}, ${Math.floor(Math.random()*256)})`); + } + } + return colors; +}; + // Call your function shuffleArray, it takes an array as a parameter and it returns a shuffled array const shuffleArray = (arr) =>{