Always getting result of 0 when counting patterns in string
<p>I keep getting a result of 0 whenever I type in a search term. I'm trying to find the number of times that a pattern occurs in string. So for example searching for <strong>at</strong> would return <strong>3</strong>. Any advice on where I'm going wrng?</p>

<pre><code>string =
[
"cat math path"
]

    var pattern = prompt('Please enter a search term:'); 

        function check(string,pattern)
        {

            if(pattern) 
            {
                if(pattern.indexOf(string) == -1) 
                {
                return 0;
                }

                return count(pattern.substring(pattern.indexOf(string)+string.length), string)+1;
            }

            else 
            {
                return("Nothing entered!");
            }
        }

        alert(check(string,pattern));
</code></pre>
