title: Javascript: How to count number of instances of a phrase in a larger string?
body: <p>I need to create a javacript function that downloads the html source code of a web page and returns the number of times a CSS class is mentioned.</p>
  
  <pre><code>var str = document.body.innerHTML;
  function getFrequency(str) {
      var freq = {};
      for (var i=0; i&lt;string.length;i++) {
          var css_class = "ENTER CLASS HERE";
          if (freq[css_class]) {
             freq[css_class]++;
          } else {
             freq[css_class] = 1;
          }
      }
  
      return freq;
  };
  </code></pre>
  
  <p>What am I doing wrong here?</p>