title: Writing a function to count the occurrences of a character in a string. [JavaScript]
body: <p>I am new to JavaScript, and I am trying to write a function that returns the number of occurrences of a given character in a string.</p>
  
  <p>So far I've gotten,</p>
  
  <pre><code>var str = "My father taught me how to throw a baseball.";
  var count = (str.match(/t/g) || []).length;
  alert(count);
  </code></pre>
  
  <p>if I run it in a JavaScript runner it works but I am not sure how to write it into a function. Any suggestions?</p>