title: JavaScript count function
body: <p>I'm trying to wring a script that outputs an array and counts the number of elements in the array based on user input. </p>
  
  <pre><code>&lt;script&gt;
      // Function searches a given array and counts the number of times an element appears in the array.
      function countOccurences(numArray, num) // function
          {                           //parameters
              var count = 0;
  
              if(array[i] == 2)
              count++;
          }
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;script&gt;
  var num = [2, 6, 33, 1, 77, 2, 98]; &lt;!-- array --&gt;
  document.write("&lt;p&gt;"+nums.toString()+"&lt;/p&gt;"); &lt;!-- fill the array--&gt;
  var count = parseFloat(prompt("Please enter number to search for", "")); &lt;!--ask for the numer to search --&gt;
  // linear search
  var p = countOccurences(nums, key) ;
  
  document.write("&lt;p&gt;Value "+p+" was not found in array &lt;/p&gt;"); //output the count
  
  &lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt; 
  </code></pre>