logo CodeStepByStep logo

hexToRGBColor

Language/Type: JavaScript loops string parameters hexadecimal rgb
Author: Melissa Hovik (on 2018/10/22)

Write a function named hexToRGBColor that takes a hexidecimal color code string in the format of "#RRGGBB" and returns the rgb code string in the format of "rgb(r, g, b)" where "r", "g", "b" are the decimal values corresponding to the hexidecimal values "RR", "GG", "BB" respectively. Recall that the range of a two-digit hexidecimal code is "00" to "FF" which corresponds to the decimal range 0 to 255, inclusive ("F" has a decimal value of 16).

For example, the call hexToRGBColor("#000000") should return the string "rgb(0, 0, 0)" and the call hexToRGBColor("#c0ffEE") should return the string "rgb(192, 255, 238)".

You may assume the passed string starts with a "#" character followed by 6 hexadecimal characters. Your function should ignore casing for the 6 non-numeric hexadecimal values (letters A thorugh F).

Function: Write a JavaScript function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.