0

I'm trying to convert RGB to HEX and when i put numbers at the function the output is correct, but when i call the function in my code it doesn't work (just the **blue **color doesn't work).

my function:

const rgbToHex = (r, g, b) => { console.log( "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1) );

return "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1); };

i tried the change the function several time but it still doesn't work the all code https://codepen.io/doron-david/pen/WNdgEOd

  • My problem David is the code you posted works as intended. Of course I used blue values in the range 0-255 when testing because the code doesn't attempt to validate input. Please add more information to the question (not as a comment) about the problem you are getting to avoid it being closed by the community. – traktor Apr 01 '22 at 11:37
  • this is the all code https://codepen.io/doron-david/pen/WNdgEOd if i get input by console log and put a num value it works, but with the input its not – DoronDavid Apr 13 '22 at 06:49
  • Please edit the question and create a minimal, runnable code snippet so readers can [reproduce the problem](https://stackoverflow.com/help/minimal-reproducible-example) (where minimal means leaving out stuff that is not needed to demonstrate the problem). During the edit change the title and include some background to clarify what the issue is, particularly given your conversion code comes from the accepted answer to the question cited as "asked before". You can search the help center for "formatting markdown" if you need help creating code snippets. – traktor Apr 13 '22 at 11:42

0 Answers0