title: Uncaught TypeError: Cannot read property 'charAt' of undefined
body: <blockquote>
    <p>code3.js:8 Uncaught TypeError: Cannot read property 'charAt' of undefined at espaces_debut (code3.js:8) at onload (Ex4.htm:11)</p>
  </blockquote>
  
  <p><strong>In Ex4.htm :</strong></p>
  
  <pre><code>&lt;html&gt;
  
  &lt;head&gt;
  &lt;title&gt;Ex4&lt;/title&gt;
  &lt;script language="javascript" src="code3.js"&gt;
  ch=prompt ("ch ") ; 
  alert (espaces_debut(ch));
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body onload="espaces_debut()"&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>IN code3.js :</strong> </p>
  
  <pre><code>function espaces_debut(ch)
  {
  i=-1;
  do 
  {
  i=i+1
  }   
  while (ch.charAt(i)=' ')  ;
  return ( ch.substr(0,i-1) ) ;   
  }
  </code></pre>
  
  <p>I get this Error , help pls </p>