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).

Type your JavaScript solution code here:


This is a function exercise. Write a JavaScript function as described. Do not write a complete program; just the function(s) above.

You must log in before you can solve this problem.

Log In

Need help?

If you do not understand how to solve an exercise or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect tests, etc.), please

Is there a problem? Contact a site administrator.

©, all rights reserved.