Help me Find the Longest Word in a String

Tell us what’s happening:

i have no idea why it keeps saying my function is undefined. can you help me

Your code so far


function findLongestWord(str) {
  var strSplit = str.split(' ');
  var longestWord = 0;
  for(var i = 0; i < strSplit.length; i++){
    if(strSplit[i].length > longestWord){
	longestWord = strSplit[i].length;
     }
  }
  return longestWord;
}
findLongestWord("The quick brown fox jumped over the lazy dog");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/find-the-longest-word-in-a-string

I just checked it on the console and the code works perfectly. Try to change your browser to chrome , may be it will work.

1 Like

Hi asutton,

The problem is the name of your function, you must use this name “findLongestWordLength” for that exercise

2 Likes