title: How to get a name of a number based on its value?
body: <p>I want to have a function <code>getNumName()</code> which, when given a number, will output a string that is that number's name and vice versa. I have not been able to achieve the former nor the latter, but the latter I've gotten frustratingly close to:</p>
  
  <pre><code>function getNameNum(num){    // string =&gt; num
      var x = document.createElement("div");
      $(x).load("https://www.google.com/search?q="+num+"+plus+zero #cwos");
      return x.innerHTML;
  }
  </code></pre>
  
  <p>Which would force Google to return its calculator, then grab that number, and return it. However, I get a CORS (Cross-Origin Request Blocked) error (Darn! Google has protection!). I had an idea for a solution for the former:</p>
  
  <pre><code>function getNumName(num){    // num -&gt; string
      var names = ["zero","one","two","three","four",...]
      return names[+num];
  }
  </code></pre>
  
  <p>But this seems highly impractical. If I have these two functions for the natural numbers, I can easily extend it to the negative numbers (with <code>Math.sign().replace("-","negative ")</code>), then extend that to the real numbers (<code>num+"".split(".")[1].split("").forEach(...)...</code>).</p>
  
  <p>The big problem is: How can I achieve these two functions? I am willing to use an external library of sorts and jQuery.</p>
  
  <ol>
  <li><code>getNameNum() -&gt; name =&gt; num</code></li>
  <li><code>getNumName() -&gt; num =&gt; name</code></li>
  </ol>