title: Iterating over a string and removing spaces Javascript Jquery
body: <p>i am trying to iterate through a string and remove all of the spaces. The js console is telling me this about line 1: Uncaught SyntaxError: Unexpected end of input.</p>
  
  <p>userinput is connected to an input tag with the id "number"</p>
  
  <p>any ideas would be appreciated. </p>
  
  <pre><code>userinput = $('input#number').val();
  
  
  function thing(x) {
      for (i = 0; i &lt;= x.length(); i++) {
          if (x.charAt(i) === (" ")) {
              return x.indexOf(i).replace("")
          }
      }
      $(document).ready(function() {
          $('form#factorial').submit(function(event) {
  
              console.log(thing(userinput));
              event.preventDefault();
  
          });
      });
  
  }
  </code></pre>