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 misplaced, put it after the loop :
function findLongestWord(str) { var words = str.split(' '); var longest = 0; for (var i=0;i longest) { longest = words[i].length; } } return longest; }