Complete the code to select the hex color value from the color picker.
const selectedColor = colorPicker.[1];The property hexValue holds the hex code of the selected color in the color picker.
Complete the code to convert the hex color to RGB format.
const rgbColor = hexToRgb([1]);The variable selectedColor holds the hex value which is passed to the hexToRgb function.
Fix the error in the code to correctly update the color preview background.
colorPreview.style.backgroundColor = [1];The backgroundColor property expects a string with the color value. Since selectedColor already contains the hex string (including '#'), it can be assigned directly.
Fill both blanks to create a function that returns true if the hex color is valid.
function isValidHex(hex) {
return /^[1]$/.test(hex);
}The regex #[0-9A-Fa-f]{6} matches a valid 6-digit hex color starting with '#'.
Fill the blanks to extract the red, green, and blue components from a hex color string.
const red = parseInt(hexColor.slice([1], [2]), 16); const green = parseInt(hexColor.slice([3], [4]), 16); const blue = parseInt(hexColor.slice([5], [6]), 16);
To extract RGB from a hex string like '#RRGGBB', slice indices are: red (1-3), green (3-5), blue (5-7).