I have a poll system and I want answers for this poll to be colored. For example: If it\'s 10% it would be red, if 40% it would be yellow and if 80% it would be green, so I
I've modified zmc's answer to give a gradient from green (0%) to red(100%).
const getGreenToRed = (percent) => { const r = 255 * percent/100; const g = 255 - (255 * percent/100); return 'rgb('+r+','+g+',0)'; }