Javascript hex number interpolation between several numbers
<p>I'm creating a "characters remaining" type counter for a site of mine, and am trying to get smooth color transitions.</p>

<p>How would I go about creating a function to obtain the hex value for a color if I pass the maximum number (in this case 300) and the current char count assuming the pattern is green, yellow, orange, red?</p>

<p>This is in Javascript. Here is what I have so far:</p>

<pre><code>function commentcounter(val) {
max = 300;
if(val &gt;= max){
    color = '#FF0000';
}else if(val &gt; (max / 2)){
    color = '#FF9900';
}else{
    color = '#00FF00';
}
display = '&lt;span style="color:' + color + '"&gt;' + val + '/' + max + '&lt;/span&gt;';
document.getElementById('counter').innerHTML = display;
}
</code></pre>

<p>As you can see, this doesn't really interpolate, just goes from green to orange to red.</p>
