title: JS switch statement inside function
body: <p>I've got a problem. I saw a possible solution but it doesn't work for me. I need to put a <code>switch</code> statement inside function because I have a lot of cases to change.</p>
  
  <p>Switch function:</p>
  
  <pre><code>var filter = function(value) {
      switch(typeof value) {
      case 'number is required':
          value = 'Number field is required!';
          break;
      }
  }
  </code></pre>
  
  <p>And i call this function inside AJAX </p>
  
  <pre><code>$.map(response.errors, function(e){
       filter(e) // I tried this and
       filter = e;
       // my code to put here in DIV.  
   })
  </code></pre>
  
  <p>Error message returns the case that I want to change. e.g: <code>&lt;div class="alert alert-success"&gt;number is required&lt;/div&gt;</code>;</p>