title: Javascript look-up function optimization
body: <p>I'm writing a custom function for my Google Sheet using Javascript, it should basically return the value based upon a table.</p>
  
  <p>I've got something that works, but feels extremely ugly with lots of nested if statements. How could this be improved for readability?</p>
  
  <pre><code>function price(msrp, order_quantity) 
  {
    var percentage;
    if(order_quantity &gt;= 200 &amp;&amp; order_quantity &lt;= 400) {
      if(msrp &gt;=49 &amp;&amp; msrp &lt;= 99) {
        percentage = 0.07;
      } else if (msrp &gt;=100 &amp;&amp; msrp &lt;= 249) {
        percentage = 0.06;
      } else if (msrp &gt;=250 &amp;&amp; msrp &lt;= 499) {
        percentage = 0.05;
      } else if (msrp &gt;=500) {
        percentage = 0.04;
      } else {
        return null;
      }
    } else if (order_quantity &gt;= 500 &amp;&amp; order_quantity &lt;= 900)  {
      if(msrp &gt;=49 &amp;&amp; msrp &lt;= 99) {
        percentage = 0.06;
      } else if (msrp &gt;=100 &amp;&amp; msrp &lt;= 249) {
        percentage = 0.05;
      } else if (msrp &gt;=250 &amp;&amp; msrp &lt;= 499) {
        percentage = 0.04;
      } else if (msrp &gt;=500) {
        percentage = 0.03;
      } else {
        return null;
      }
    } else if (order_quantity &gt;= 1000 &amp;&amp; order_quantity &lt;= 1400)  {
      if(msrp &gt;=49 &amp;&amp; msrp &lt;= 99) {
        percentage = 0.07;
      } else if (msrp &gt;=100 &amp;&amp; msrp &lt;= 249) {
        percentage = 0.06;
      } else if (msrp &gt;=250 &amp;&amp; msrp &lt;= 499) {
        percentage = 0.05;
      } else if (msrp &gt;=500) {
        percentage = 0.04;
      } else {
        return null;
      }
    } else if (order_quantity &gt;= 1500)  {
      if(msrp &gt;=49 &amp;&amp; msrp &lt;= 99) {
        percentage = 0.04;
      } else if (msrp &gt;=100 &amp;&amp; msrp &lt;= 249) {
        percentage = 0.03;
      } else if (msrp &gt;=250 &amp;&amp; msrp &lt;= 499) {
        percentage = 0.025;
      } else if (msrp &gt;=500) {
        percentage = 0.015;
      } else {
        return null;
      }
    } else {
      return null;
    }
    return msrp * percentage;
  }
  </code></pre>