I\'m trying to find the longest word in a string, but it continually returns the length of the first word. Any ideas?
Here\'s my code:
function findL
Your return statement is in the wrong place, as mccainz said, however you should also be saving the word if you want to return the actual word.
function findLongestWord(str) {
var words = str.split(' ');
var longestLength = 0;
var longestWord;
for (var i=0;i longestLength) {
longestLength = words[i].length;
longestWord = words[i];
}
}
return longestWord;
}