Question: Assuming:
str value = 'This is some text';

I want to count how many 't' occurrences, how to do that?

Answer: 
An easy solution is to loop

```
var count = 0;
for(var i = 0; i < str.length; i ++) {
  if(str.charAt(i) === 't')
    ++count;
}

```

You might also want to use `str.toLowerCase();` if you don't want to be case sensitive.
```
<button onclick="alert(countCharacter('abcdea', 'a'));"> Test! </button>

<script type="text/javascript">
    function countCharacter(sample, characterToFind) {
        var result = 0;

        for(i = 0;i<sample.length;i++) {
            if(sample[i] === characterToFind) {
                result++;
            }
        }

        return result;
    }
</script>

```