← Back to challenges

RGB to Hex Color Converter

JavaScriptHardarraysobjectsstrings

Instructions

Create a function that converts color in RGB format to Hex format.

Examples

rgbToHex("rgb(0, 128, 192)") ➞ "#0080c0"

rgbToHex("rgb(45, 255, 192)") ➞ "#2dffc0"

rgbToHex("rgb(0, 0, 0)") ➞ "#000000"

Notes

The Hex format should be displayed in lowercase.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.