Find the Longest Word in a String - can't find an error

Can someone help me to find an error?
Your code so far

function findLongestWord(str) {
  str = str.split(' ');
  var maxLength = 0;
  var indexMaxLength = 0;
  for (var i = 0;i<str.length;i++){
    if(str[i].length>maxLength){
      maxLength=str[i].length;
      indexMaxLength=i;
    }
  }
  return indexMaxLength;
}

findLongestWord("The quick brown fox jumped over the lazy dog");

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36.

Link to the challenge:

You are returning the index of the longest word, but you should return the length of the longest word.

1 Like

Thank you! :stuck_out_tongue::stuck_out_tongue::stuck_out_tongue: