javascript - indexOf is not a funciton -
i have event...
<textarea id="chat"> </textarea> <button type="button" onclick="play_song();">talk</button>
... triggering following function
:
var input = function() { var chat = document.getelementbyid("chat").value.split(" "); return chat && console.log(chat); }
then there's function
:
function setintersection(a, b) { var result = []; (var = 0; < a.length; i++) { if (b.indexof(a[i]) !== -1 && result.indexof(a[i]) === -1) { result.push(a[i]); } } return result; }
a prototype function
:
song.prototype.lyricsintersect = function(input) { var bestsong = null; var bestcount = -infinity; (var in songs) { var currentcount = setintersection(songs[i].lyrics, input).length; if (currentcount > bestcount) { bestsong = songs[i]; bestcount = currentcount; } } return bestsong && bestsong.name; }
the code ends here:
function play_song() { var id = song.prototype.lyricsintersect(input); var element = document.getelementbyid(id); element.play(); }
but console.log
returns: uncaught typeerror: b.indexof not function
if test var input = ["one", "two"];
, however, intersection done on code depending on input
.
what missing?
var currentcount = setintersection(songs[i].lyrics, input).length;
should be
var currentcount = setintersection(songs[i].lyrics, input()).length;
this relies on input being corrected follows
var input = function() { var chat = document.getelementbyid("chat").value.split(" "); return chat; }
Comments
Post a Comment