title: Javascript numbers to words - vigesimal 200-999
body: <p>I've successfully built a numbers to words converter for 1-199, for a foreign language that uses a vigesimal number system, counting in twenties. I'd now like to add 200-999.</p>
  
  <p>Here's what I have so far. HTML:</p>
  
  <pre><code>&lt;table align=center&gt;
  &lt;tr&gt;&lt;td&gt;
  &lt;form action="#" name="conv"&gt;
  Enter number:
  &lt;input type="text" name="numb" size="15"&gt;
  &lt;input type="button" value="Show number" onclick="getnum(document.conv.numb.value)"&gt;
  &lt;/form&gt;
  &lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td align=center&gt;&lt;span id="outp"&gt;&amp;nbsp;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>Javascript:</p>
  
  <pre><code>var units = new Array(21)
  units[0]=""
  units[1]="onen"
  units[2]="dew"
  units[3]="tri"
  units[4]="pajar"
  units[5]="pemp"
  units[6]="whegh"
  units[7]="seyth"
  units[8]="eth"
  units[9]="naw"
  units[10]="deg"
  units[11]="udnek"
  units[12]="dowdhek"
  units[13]="tredhek"
  units[14]="peswardhek"
  units[15]="pemthek"
  units[16]="whetek"
  units[17]="seytek"
  units[18]="etek"
  units[19]="nownsek"
  units[20]="ugens"
  
  function getnum(s){
      var n = parseInt(s);
  
      if( 1 &lt;= n &amp;&amp; n &lt;= 20 ){ alert(units[n]); }
  
      if( 21 &lt;= n &amp;&amp; n &lt;= 39 ){
        var r = Math.floor(n - 20);
  
        r &amp;&amp; (alert (units[r] + ' warn ' + units[20]));
      }
  
      if( (40 &lt;= n &amp;&amp; n &lt;= 99) || (120 &lt;= n &amp;&amp; n &lt;= 199) ){
        var q = Math.floor(n / 20);
        var r = n % 20;
  
        !r &amp;&amp; (alert (units[q] + ' ' + units[20]));
  
        r &amp;&amp; (alert (units[r] + ' ha ' + units[q] + ' ' + units[20]));
      }
  
      if( 100 &lt;= n &amp;&amp; n &lt;= 100 ){ alert('cans'); }
  
      if( 101 &lt;= n &amp;&amp; n &lt;= 119 ){
        var r = Math.floor(n - 100);
  
          r &amp;&amp; (alert ('cans ha ' + units[r]));
      }
  } 
  </code></pre>
  
  <p>The trouble with 200-999 is that I think I need to specify separate rules within each hundred - for example within the 200s, 200-220 is "two hundred and x", but 221-299 is "two hundred one and twenty" to "two hundred nineteen and four twenty", using the same vigesimal system as 21-99. How can I expand the code I already have to allow me to add 200-999?</p>
  
  <p>These are the words for the hundreds - it needs to be done this way because of the exception "tri hans" (unless there's a better way to account for it)</p>
  
  <pre><code>var hundreds = new Array(11)
  hundreds[0]=""
  hundreds[1]="cans"
  hundreds[2]="dew cans"
  hundreds[3]="tri hans"
  hundreds[4]="pajar cans"
  hundreds[5]="pemp cans"
  hundreds[6]="whegh cans"
  hundreds[7]="seyth cans"
  hundreds[8]="eth cans"
  hundreds[9]="naw cans"
  hundreds[10]="mil"
  </code></pre>
  
  <p>Thanks</p>