title: Uncaught RangeError: Invalid string length in JavaScript
body: <p>I have a JavaScript function:</p>
  <pre class="lang-js prettyprint-override"><code>function addcontent(ele, text, lines, separate_lines){
  
      if(separate_lines){
      for(i=0; i&lt;lines; i++){
        text=text+&quot;\n&quot;+text+&quot;\n&quot;;
      }
    }
  
      else if(!separate_lines){
      for(e=0; e&lt;lines; e++){
        text=text+text;
      }
    }
  
      ele.append(text);
  
    }
  </code></pre>
  <p>and when I use it for the onclick of an HTML Button like:</p>
  <pre class="lang-html prettyprint-override"><code>&lt;button onclick=&quot;addcontent(document.body, 'A', 100, true)&quot;&gt;
      Add content.
    &lt;/button&gt;
  </code></pre>
  <p>I get this error in the Chrome console when I click the button:</p>
  <blockquote>
  <p>Uncaught RangeError: Invalid string length
  at addcontent
  at HTMLButtonElement.onclick</p>
  </blockquote>
  <p>I have no idea where I'm wrong.</p>