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.
So far I've gotten,
var str = "My father taught me how to throw a baseball.";
var count = (str.match(/t/g) || []).length;
alert(count);
if I run it in a JavaScript runner it works but I am not sure how to write it into a function. Any suggestions?