title: javascript - indexOf is not a funciton
body: <p>I have this event...</p>
  
  <pre><code>   &lt;textarea id="chat"&gt; &lt;/textarea&gt;
     &lt;button type="button" onclick="play_song();"&gt;talk&lt;/button&gt;
  </code></pre>
  
  <p>... triggering the following <code>function</code>:</p>
  
  <pre><code>   var input = function() {
             var chat = document.getElementById("chat").value.split(" ");
             return chat &amp;&amp; console.log(chat);
          }
  </code></pre>
  
  <p>then there's this <code>function</code>:</p>
  
  <pre><code>   function setIntersection(a, b) {
  
        var result = [];
  
        for (var i = 0; i &lt; a.length; i++) {
           if (b.indexOf(a[i]) !== -1 &amp;&amp; result.indexOf(a[i]) === -1) {
              result.push(a[i]);
           }
        }
      return result;
     }
  </code></pre>
  
  <p>a <code>prototype function</code>:</p>
  
  <pre><code>   Song.prototype.lyricsIntersect = function(input) {
  
  
        var bestSong = null;
        var bestCount = -Infinity;
  
        for (var i in songs) {
          var currentCount = setIntersection(songs[i].lyrics, input).length;
  
      if (currentCount &gt; bestCount) {
          bestSong = songs[i];
          bestCount = currentCount;
      }
  }
  
  return bestSong &amp;&amp; bestSong.name;
  }
  </code></pre>
  
  <p>the code ends here:</p>
  
  <pre><code>   function play_song() {
  
      var id = Song.prototype.lyricsIntersect(input);
      var element = document.getElementById(id);
      element.play();
  }
  </code></pre>
  
  <p>but <code>console.log</code> returns: <code>Uncaught TypeError: b.indexOf is not a function</code></p>
  
  <p>if I test <code>var input = ["one", "two"];</code>, however, I get the intersection done on the code depending on <code>input</code>.</p>
  
  <p>what am I missing?</p>